Commit 7d3d3dec authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

tweaks: use the logic from revstrstr() also in mbrevstrcasestr()

Because it is slightly faster.
parent 6240805c
Showing with 9 additions and 9 deletions
+9 -9
......@@ -535,29 +535,29 @@ char *mbrevstrcasestr(const char *haystack, const char *needle,
{
#ifdef ENABLE_UTF8
if (use_utf8) {
size_t tail_len, needle_len;
size_t needle_len = mbstrlen(needle);
size_t tail_len = mbstrlen(pointer);
if (*needle == '\0')
if (needle_len == 0)
return (char *)pointer;
needle_len = mbstrlen(needle);
if (mbstrlen(haystack) < needle_len)
return NULL;
tail_len = mbstrlen(pointer);
if (tail_len < needle_len)
pointer += tail_len - needle_len;
if (pointer < haystack)
return NULL;
while (TRUE) {
if (tail_len >= needle_len &&
mbstrncasecmp(pointer, needle, needle_len) == 0)
if (mbstrncasecmp(pointer, needle, needle_len) == 0)
return (char *)pointer;
/* If we've reached the head of the haystack, we found nothing. */
if (pointer == haystack)
return NULL;
pointer = haystack + move_mbleft(haystack, pointer - haystack);
tail_len++;
}
} else
#endif
......
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