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
parent
7d3d3dec9a
commit
1a79b3d514
|
@ -487,9 +487,6 @@ char *revstrstr(const char *haystack, const char *needle,
|
||||||
if (needle_len == 0)
|
if (needle_len == 0)
|
||||||
return (char *)pointer;
|
return (char *)pointer;
|
||||||
|
|
||||||
if (strlen(haystack) < needle_len)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (tail_len < needle_len)
|
if (tail_len < needle_len)
|
||||||
pointer += 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)
|
if (needle_len == 0)
|
||||||
return (char *)pointer;
|
return (char *)pointer;
|
||||||
|
|
||||||
if (strlen(haystack) < needle_len)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (tail_len < needle_len)
|
if (tail_len < needle_len)
|
||||||
pointer += 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)
|
if (needle_len == 0)
|
||||||
return (char *)pointer;
|
return (char *)pointer;
|
||||||
|
|
||||||
if (mbstrlen(haystack) < needle_len)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (tail_len < needle_len)
|
if (tail_len < needle_len)
|
||||||
pointer += tail_len - needle_len;
|
pointer += tail_len - needle_len;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue