diff options
| author | Junio C Hamano <gitster@pobox.com> | 2009-03-21 23:08:21 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2009-03-21 23:08:21 -0700 |
| commit | 2aa93deec047763cff750196610268fd7227cfc9 (patch) | |
| tree | 5720a44a9e2d557bfd4265083c54aba48dec4c10 /diffcore-pickaxe.c | |
| parent | Merge branch 'js/rsync-local' into maint (diff) | |
| parent | optimize compat/ memmem() (diff) | |
| download | git-2aa93deec047763cff750196610268fd7227cfc9.tar.gz git-2aa93deec047763cff750196610268fd7227cfc9.zip | |
Merge branch 'rs/memmem' into maint
* rs/memmem:
optimize compat/ memmem()
diffcore-pickaxe: use memmem()
Diffstat (limited to 'diffcore-pickaxe.c')
| -rw-r--r-- | diffcore-pickaxe.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index af9fffe6e8..574b3e8337 100644 --- a/diffcore-pickaxe.c +++ b/diffcore-pickaxe.c @@ -10,7 +10,7 @@ static unsigned int contains(struct diff_filespec *one, regex_t *regexp) { unsigned int cnt; - unsigned long offset, sz; + unsigned long sz; const char *data; if (diff_populate_filespec(one, 0)) return 0; @@ -33,15 +33,13 @@ static unsigned int contains(struct diff_filespec *one, } } else { /* Classic exact string match */ - /* Yes, I've heard of strstr(), but the thing is *data may - * not be NUL terminated. Sue me. - */ - for (offset = 0; offset + len <= sz; offset++) { - /* we count non-overlapping occurrences of needle */ - if (!memcmp(needle, data + offset, len)) { - offset += len - 1; - cnt++; - } + while (sz) { + const char *found = memmem(data, sz, needle, len); + if (!found) + break; + sz -= found - data + len; + data = found + len; + cnt++; } } diff_free_filespec_data(one); |
