From 1a79b3d5147050ae73942ee098dce36cf9b59deb Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 30 Apr 2017 18:12:13 +0200 Subject: [PATCH] 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. --- src/chars.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/chars.c b/src/chars.c index ba134d5e..a7200f94 100644 --- 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;