diff options
author | Wilco Dijkstra <wdijkstr@arm.com> | 2018-07-16 17:50:09 +0100 |
---|---|---|
committer | Wilco Dijkstra <wdijkstr@arm.com> | 2018-07-16 17:51:52 +0100 |
commit | 3ae725dfb6d7f61447d27d00ed83e573bd5454f4 (patch) | |
tree | 1a0eada529fc06de4613cb84a20d80e5d69c6d0a /string/strstr.c | |
parent | x86_64: Undef SHADOW_STACK_POINTER_OFFSET last (diff) | |
download | glibc-3ae725dfb6d7f61447d27d00ed83e573bd5454f4.tar.gz glibc-3ae725dfb6d7f61447d27d00ed83e573bd5454f4.tar.bz2 glibc-3ae725dfb6d7f61447d27d00ed83e573bd5454f4.zip |
Improve strstr performance
Improve strstr performance. Strstr tends to be slow because it uses
many calls to memchr and a slow byte loop to scan for the next match.
Performance is significantly improved by using strnlen on larger blocks
and using strchr to search for the next matching character. strcasestr
can also use strnlen to scan ahead, and memmem can use memchr to check
for the next match.
On the GLIBC bench tests the performance gains on Cortex-A72 are:
strstr: +25%
strcasestr: +4.3%
memmem: +18%
On a 256KB dataset strstr performance improves by 67%, strcasestr by 47%.
Reviewd-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'string/strstr.c')
-rw-r--r-- | string/strstr.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/string/strstr.c b/string/strstr.c index b3b5deb673..265e9f310c 100644 --- a/string/strstr.c +++ b/string/strstr.c @@ -33,10 +33,11 @@ #define RETURN_TYPE char * #define AVAILABLE(h, h_l, j, n_l) \ - (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ - && ((h_l) = (j) + (n_l))) + (((j) + (n_l) <= (h_l)) || ((h_l) += __strnlen ((void*)((h) + (h_l)), 512), \ + (j) + (n_l) <= (h_l))) #define CHECK_EOL (1) #define RET0_IF_0(a) if (!a) goto ret0 +#define FASTSEARCH(S,C,N) (void*) strchr ((void*)(S), (C)) #include "str-two-way.h" #undef strstr |