[PATCH 1/4] Improve generic strcspn performance

Adhemerval Zanella adhemerval.zanella@linaro.org
Thu Mar 31 18:28:00 GMT 2016



On 31-03-2016 11:49, Wilco Dijkstra wrote:
> 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
> 

Right, I will change that.



More information about the Libc-alpha mailing list