[PATCH] Do not transform strchr into rawmemchr
Zack Weinberg
zackw@panix.com
Wed Nov 16 19:02:00 GMT 2016
On Wed, Nov 16, 2016 at 1:59 PM, Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
> GLIBC uses strchr (s, '\0') as an idiom to find the end of a string.
> This is transformed into rawmemchr by the bits/string2.h header.
> However this is generally slower than strlen on most targets, even when
> an optimized rawmemchr implementation exists. Since GCC7 optimizes
> strchr (s, '\0') to strlen (s) + s, the GLIBC headers should not
> transform this to rawmemchr.
I endorse the removal of the non-optimization, but ...
> #ifndef _HAVE_STRING_ARCH_strchr
> -extern void *__rawmemchr (const void *__s, int __c);
> -# define strchr(s, c) \
> - (__extension__ (__builtin_constant_p (c) && !__builtin_constant_p (s) \
> - && (c) == '\0' \
> - ? (char *) __rawmemchr (s, c) \
> - : __builtin_strchr (s, c)))
> +# define strchr(s, c) __builtin_strchr (s, c)
> #endif
... wouldn't it be just as effective to remove this block entirely?
That is, don't #define strchr at all.
zw
More information about the Libc-alpha
mailing list