commit 1a79b3d5147050ae73942ee098dce36cf9b59deb
parent 7d3d3dec9a94734f8c8d9b2b019dfbec05f38798
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Sun, 30 Apr 2017 18:12:13 +0200
tweaks: remove a superfluous strlen() call from the reverse searches
If the length of the haystack is smaller than the length of the needle,
this means that also the length of the tail will be smaller -- because
pointer will be bigger than or equal to haystack -- so the pointer gets
readjusted to be a needle length before the end of the haystack, which
means that it ends up /before/ the haystack: thus the while loop will
never run.
On average, this saves some 200 nanoseconds per line.
Diffstat:
1 file changed, 0 insertions(+), 9 deletions(-)
diff --git a/src/chars.c b/src/chars.c
@@ -487,9 +487,6 @@ char *revstrstr(const char *haystack, const char *needle,
if (needle_len == 0)
return (char *)pointer;
- if (strlen(haystack) < needle_len)
- return NULL;
-
if (tail_len < needle_len)
pointer += tail_len - needle_len;
@@ -513,9 +510,6 @@ char *revstrcasestr(const char *haystack, const char *needle,
if (needle_len == 0)
return (char *)pointer;
- if (strlen(haystack) < needle_len)
- return NULL;
-
if (tail_len < needle_len)
pointer += tail_len - needle_len;
@@ -541,9 +535,6 @@ char *mbrevstrcasestr(const char *haystack, const char *needle,
if (needle_len == 0)
return (char *)pointer;
- if (mbstrlen(haystack) < needle_len)
- return NULL;
-
if (tail_len < needle_len)
pointer += tail_len - needle_len;