From d58ab810a6e325cc351684d174c48cabce01bcc1 Mon Sep 17 00:00:00 2001 From: Wilco Dijkstra Date: Wed, 14 Dec 2016 15:12:18 +0000 Subject: Improve strtok and strtok_r performance. Instead of calling strpbrk which calls strcspn, call strcspn directly so we get the end of the token without an extra call to rawmemchr. Also avoid an unnecessary call to strcspn after the last token by adding an early exit for an empty string. Change strtok to tailcall strtok_r to avoid unnecessary code duplication. Remove the special header optimization for strtok_r of a 1-character constant string - both strspn and strcspn contain optimizations for this case. Benchmarking this showed similar performance in the worst case, but up to 5.5x better performance in the "found" case for large inputs. * benchtests/bench-strtok.c (oldstrtok): Add old implementation. * string/strtok.c (strtok): Change to tailcall __strtok_r. * string/strtok_r.c (__strtok_r): Optimize for performance. * string/string-inlines.c (__old_strtok_r_1c): New function. * string/bits/string2.h (__strtok_r): Move to string-inlines.c. --- ChangeLog | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ChangeLog') diff --git a/ChangeLog b/ChangeLog index e9f41247b6..f7128edc44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-12-14 Wilco Dijkstra + + * benchtests/bench-strtok.c (oldstrtok): Add old implementation. + * string/strtok.c (strtok): Change to tailcall __strtok_r. + * string/strtok_r.c (__strtok_r): Optimize for performance. + * string/string-inlines.c (__old_strtok_r_1c): New function. + * string/bits/string2.h (__strtok_r): Move to string-inlines.c. + 2016-12-14 Gabriel F. T. Gomes * math/Makefile (gen-libm-calls): Add w_log1pF. -- cgit v1.2.3