This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/4] Improve generic strcspn performance
- From: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Cc: nd <nd at arm dot com>
- Date: Thu, 31 Mar 2016 14:49:00 +0000
- Subject: Re: [PATCH 1/4] Improve generic strcspn performance
- Authentication-results: sourceware.org; auth=none
- Nodisclaimer: True
- References: <1459432863-20749-1-git-send-email-adhemerval dot zanella at linaro dot org>,<1459432863-20749-2-git-send-email-adhemerval dot zanella at linaro dot org>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:23
Adhemerval Zanella wrote:
size_t
-STRCSPN (const char *s, const char *reject)
+STRCSPN (const char *str, const char *reject)
{
- size_t count = 0;
+ if (reject[0] == '\0' || reject[1] == '\0')
+ return __strchrnul (str, reject [0]) - str;
I agree using __strchrnul is fine if reject[0] == '\0' as that should be very rare.
However it needs __glibc_unlikely again to avoid slowing down the common case.
It's odd that GCC doesn't predict that the first character(s) of a string are non-zero...
Other than that, it looks good.
Wilco