diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-03-11 13:49:42 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-03-11 13:49:42 -0700 |
commit | 8f4cc7911955a3642af601394a4b4473e7bfde33 (patch) | |
tree | 3c692d0737f27703365c0e2b495259e0636b2697 /compat | |
parent | e43997979ecc69bb9b9720a080a3897738e00f19 (diff) | |
parent | 56384e61ead8d41c39bfafb535eedcf67ef4fcc3 (diff) | |
download | git-8f4cc7911955a3642af601394a4b4473e7bfde33.tar.gz |
Merge branch 'rs/memmem'
* rs/memmem:
optimize compat/ memmem()
diffcore-pickaxe: use memmem()
Diffstat (limited to 'compat')
-rw-r--r-- | compat/memmem.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/compat/memmem.c b/compat/memmem.c index cd0d877364..56bcb4277f 100644 --- a/compat/memmem.c +++ b/compat/memmem.c @@ -5,6 +5,8 @@ void *gitmemmem(const void *haystack, size_t haystack_len, { const char *begin = haystack; const char *last_possible = begin + haystack_len - needle_len; + const char *tail = needle; + char point; /* * The first occurrence of the empty string is deemed to occur at @@ -20,8 +22,9 @@ void *gitmemmem(const void *haystack, size_t haystack_len, if (haystack_len < needle_len) return NULL; + point = *tail++; for (; begin <= last_possible; begin++) { - if (!memcmp(begin, needle, needle_len)) + if (*begin == point && !memcmp(begin + 1, tail, needle_len - 1)) return (void *)begin; } |