This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Use strlen when searching for a nul char
- From: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- To: Mike Frysinger <vapier at gentoo dot org>
- Cc: 'GNU C Library' <libc-alpha at sourceware dot org>, nd <nd at arm dot com>
- Date: Wed, 20 Apr 2016 15:52:41 +0000
- Subject: Re: [PATCH] Use strlen when searching for a nul char
- Authentication-results: sourceware.org; auth=none
- Nodisclaimer: True
- References: <DB3PR08MB008978DA72CE0E1B93BB477483A60 at DB3PR08MB0089 dot eurprd08 dot prod dot outlook dot com> <20160419175706 dot GI5369 at vapier dot lan> <AM3PR08MB0088C41881332E9D5DF94BCC836C0 at AM3PR08MB0088 dot eurprd08 dot prod dot outlook dot com> <20160419222134 dot GQ5369 at vapier dot lan> <AM3PR08MB0088858A7DD08414E65F8375836D0 at AM3PR08MB0088 dot eurprd08 dot prod dot outlook dot com>,<20160420152413 dot GC5369 at vapier dot lan>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:23
Mike Frysinger wrote:
> this relies on _HAVE_STRING_ARCH_strchr & _HAVE_STRING_ARCH_rawmemchr
> being in sync in order for the strchr->strlen rewrite. should we just
> do the strlen change in strchr itself too ?
If a target only defines _HAVE_STRING_ARCH_rawmemchr then presumably
it supports a fast rawmemchr, so it might be expected that strchr defers to rawmemchr
as it does today rather than using strlen.
If a target only defines _HAVE_STRING_ARCH_strchr then rawmemchr
would still use strlen, which is fine.
Wilco
> #ifndef _HAVE_STRING_ARCH_strchr
> extern void *__rawmemchr (const void *__s, int __c);
> -# define strchr(s, c) \
> +# define strchr(s, c) \
> (__extension__ (__builtin_constant_p (c) && !__builtin_constant_p (s) \
> && (c) == '\0' \
> ? (char *) __rawmemchr (s, c) \
> : __builtin_strchr (s, c)))
> #endif
>
> +#ifndef _HAVE_STRING_ARCH_rawmemchr
> +extern void *__rawmemchr (const void *__s, int __c);
> +# define __rawmemchr(s, c) \
> + (__extension__ ({ char *__s = (char *)(s); \
> + __builtin_constant_p (c) && (c) == '\0' \
> + ? (void *)(__s + strlen (__s)) \
> + : __rawmemchr (__s, (c));}))
> +# ifdef __USE_GNU
> +# define rawmemchr(s,c) __rawmemchr ((s), (c))
> +# endif
> +#endif