From: James Tirta Halim <tirtajames45@gmail.com>
To: libc-alpha@sourceware.org
Cc: James Tirta Halim <tirtajames45@gmail.com>
Subject: [PATCH] Avoid double bounds check at the start of the loop
Date: Mon, 4 Sep 2023 21:56:51 +0700 [thread overview]
Message-ID: <20230904145651.1449926-1-tirtajames45@gmail.com> (raw)
---
string/memmem.c | 4 ++--
string/strstr.c | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/string/memmem.c b/string/memmem.c
index 13df3bcdd4..dea3e5a29c 100644
--- a/string/memmem.c
+++ b/string/memmem.c
@@ -92,7 +92,7 @@ __memmem (const void *haystack, size_t hs_len,
shift1 = m1 - shift[hash2 (ne + m1)];
shift[hash2 (ne + m1)] = m1;
- for ( ; hs <= end; )
+ do
{
/* Skip past character pairs not in the needle. */
do
@@ -121,7 +121,7 @@ __memmem (const void *haystack, size_t hs_len,
/* Skip based on matching the hash of the needle end. */
hs += shift1;
- }
+ } while (hs <= end);
return NULL;
}
libc_hidden_def (__memmem)
diff --git a/string/strstr.c b/string/strstr.c
index 23618e2eb2..7ec812b931 100644
--- a/string/strstr.c
+++ b/string/strstr.c
@@ -121,6 +121,7 @@ STRSTR (const char *haystack, const char *needle)
shift1 = m1 - shift[hash2 (ne + m1)];
shift[hash2 (ne + m1)] = m1;
+ goto start;
while (1)
{
if (__glibc_unlikely (hs > end))
@@ -130,6 +131,7 @@ STRSTR (const char *haystack, const char *needle)
return NULL;
}
+start:
/* Skip past character pairs not in the needle. */
do
{
--
2.42.0
next reply other threads:[~2023-09-04 14:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-04 14:56 James Tirta Halim [this message]
2023-09-06 10:58 Wilco Dijkstra
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=20230904145651.1449926-1-tirtajames45@gmail.com \
--to=tirtajames45@gmail.com \
--cc=libc-alpha@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: link
Be 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).