[PATCH] Use strlen when searching for a nul char
Mike Frysinger
vapier@gentoo.org
Tue Apr 19 17:57:00 GMT 2016
On 25 Feb 2016 13:04, Wilco Dijkstra wrote:
> Remove the strchr (s, '\0') to rawmemchr optimization as using rawmemchr is
> a bad idea - I have a patch to add strchr (s, '\0') -> strlen to GCC7.
> Like strchr (s, '\0'), rawmemchr (s, '\0') appears a common idiom for finding
> the end of a string, however it is not the most efficient way of doing so.
> Strlen is a simpler operation which is significantly faster on larger inputs
> (eg. on x86 strlen is 50% faster than rawmemchr on strings of 1KB).
will there be a change in GCC to also detect rawmemchr(s,'\0') ?
even then, since this optimization isn't showing up until GCC7, shouldn't
we keep some logic here ? i.e. transform strchr/rawmemchr(s, '\0') into
strlen before falling back ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20160419/3260625f/attachment.sig>
More information about the Libc-alpha
mailing list