aboutsummaryrefslogtreecommitdiff
path: root/string
diff options
context:
space:
mode:
authorRajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>2018-08-28 12:42:19 +0530
committerRajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>2018-08-28 12:42:19 +0530
commitc8dd67e7c958de04c3783cbea7c384431707b5f8 (patch)
treee2598bc72869dcb1fad19f600d9147539d441708 /string
parent5abedf97a3d396798cb48a3bf86f322d71955ad9 (diff)
downloadglibc-c8dd67e7c958de04c3783cbea7c384431707b5f8.zip
glibc-c8dd67e7c958de04c3783cbea7c384431707b5f8.tar.gz
glibc-c8dd67e7c958de04c3783cbea7c384431707b5f8.tar.bz2
Speedup first memmem match
As done in commit 284f42bc778e487dfd5dff5c01959f93b9e0c4f5, memcmp can be used after memchr to avoid the initialization overhead of the two-way algorithm for the first match. This has shown improvement >40% for first match.
Diffstat (limited to 'string')
-rw-r--r--string/memmem.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/string/memmem.c b/string/memmem.c
index 43efaa3..d72b824 100644
--- a/string/memmem.c
+++ b/string/memmem.c
@@ -70,6 +70,10 @@ __memmem (const void *haystack_start, size_t haystack_len,
haystack_len -= haystack - (const unsigned char *) haystack_start;
if (haystack_len < needle_len)
return NULL;
+ /* Check whether we have a match. This improves performance since we
+ avoid the initialization overhead of the two-way algorithm. */
+ if (memcmp (haystack, needle, needle_len) == 0)
+ return (void *) haystack;
return two_way_short_needle (haystack, haystack_len, needle, needle_len);
}
else