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.
master
Benno Schulenberg 2017-04-30 18:12:13 +02:00
parent 7d3d3dec9a
commit 1a79b3d514
1 changed files with 0 additions and 9 deletions

View File

@ -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;