]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Speedup first memmem match
authorRajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
Tue, 28 Aug 2018 07:12:19 +0000 (12:42 +0530)
committerWilco Dijkstra <wdijkstr@arm.com>
Fri, 13 Sep 2019 15:40:20 +0000 (16:40 +0100)
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.

(cherry picked from commit c8dd67e7c958de04c3783cbea7c384431707b5f8)

ChangeLog
string/memmem.c

index 22012fb4589bfabdfc1d9892b5742c77819020c5..12e7d27e4903aab31461e6a090ea525189b919ef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 34299b886448387ed475320c8de92246da734fac..645b6d1a267bc6b98a6f9641b4177397bb5bb8f7 100644 (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