1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

Speedup first memmem match

As done in commit 284f42bc77, 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.
This commit is contained in:
Rajalakshmi Srinivasaraghavan
2018-08-28 12:42:19 +05:30
parent 5abedf97a3
commit c8dd67e7c9
2 changed files with 8 additions and 0 deletions

View File

@ -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