Commit 1a79b3d5 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

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.
parent 7d3d3dec
Showing with 0 additions and 9 deletions
+0 -9
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment