X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=diffcore-pickaxe.c;h=574b3e833711fe3794636b86dbf2b9d9deb5e151;hb=de7697808fd8b552479a60fa3b98440d541b42de;hp=c4a77d71da5602b68c541c2487fcbecfdfff2944;hpb=1b2782a5e2f88bf5e6e2cbb58e54fea015e21af5;p=git.git diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index c4a77d71d..574b3e833 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); @@ -102,7 +100,7 @@ void diffcore_pickaxe(const char *needle, int opts) for (i = 0; i < q->nr; i++) diff_free_filepair(q->queue[i]); } - else + else /* Showing only the filepairs that has the needle */ for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i];