From 3ebcc813dc643fc0853ebc159fa5b6e747258933 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 13 Nov 2015 22:01:11 +0100 Subject: improve performance on strstr and wcsstr if the needle is one character wide MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/string/strstr.c | 2 ++ src/wchar/wcsstr.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/string/strstr.c b/src/string/strstr.c index a2c31f6..f396570 100644 --- a/src/string/strstr.c +++ b/src/string/strstr.c @@ -37,6 +37,8 @@ */ char* (strstr)(const char* haystack, const char* needle) { + if (*needle && !(needle[1])) + return (strchr)(haystack, *needle); return (memmem)(haystack, strlen(haystack), needle, strlen(needle)); } diff --git a/src/wchar/wcsstr.c b/src/wchar/wcsstr.c index 36ae893..b0600e1 100644 --- a/src/wchar/wcsstr.c +++ b/src/wchar/wcsstr.c @@ -33,6 +33,8 @@ */ wchar_t* (wcswcs)(const wchar_t* haystack, const wchar_t* needle) { + if (*needle && !(needle[1])) + return (wcschr)(haystack, *needle); return (wcsstr)(haystack, needle); } -- cgit v1.2.3-70-g09d2