mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-13 06:40:09 +00:00
Speedup first memmem match
As done in commit284f42bc77
, 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. (cherry picked from commitc8dd67e7c9
)
This commit is contained in:
parent
c60bf879b2
commit
ceeba1d73c
@ -1,3 +1,7 @@
|
||||
2019-09-13 Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
|
||||
|
||||
* string/memmem.c: Use memcmp for first match.
|
||||
|
||||
2019-09-13 Wilco Dijkstra <wdijkstr@arm.com>
|
||||
|
||||
* string/strcasestr.c (STRCASESTR): Simplify and speedup first match.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user