summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-03-11 13:49:42 -0700
committerJunio C Hamano <gitster@pobox.com>2009-03-11 13:49:42 -0700
commit8f4cc7911955a3642af601394a4b4473e7bfde33 (patch)
tree3c692d0737f27703365c0e2b495259e0636b2697 /compat
parente43997979ecc69bb9b9720a080a3897738e00f19 (diff)
parent56384e61ead8d41c39bfafb535eedcf67ef4fcc3 (diff)
downloadgit-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.c5
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;
}