public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Tulio Magno Quites Machado Filho <tuliom@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/ibm/2.28/master] Speedup first memmem match Date: Fri, 22 Nov 2019 18:53:00 -0000 [thread overview] Message-ID: <20191122185339.9704.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d6ccf2f45c5e09d3a36321ba695325589e8940fe commit d6ccf2f45c5e09d3a36321ba695325589e8940fe Author: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com> Date: Tue Aug 28 12:42:19 2018 +0530 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. (cherry picked from commit c8dd67e7c958de04c3783cbea7c384431707b5f8) Diff: --- ChangeLog | 4 ++++ string/memmem.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1455310..182e0ba 100644 --- 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. 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
reply other threads:[~2019-11-22 18:53 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191122185339.9704.qmail@sourceware.org \ --to=tuliom@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).