[PATCH] memchr.3: Deprecate rawmemchr(3)

Wilco Dijkstra Wilco.Dijkstra@arm.com
Fri Jan 6 12:57:03 GMT 2023


Hi Alex,

> It is not optimized, and it calls either strlen(3) or memchr(3), so the
> caller can do it directly, and it will be better.
>
> Suggested-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
> Signed-off-by: Alejandro Colomar <alx@kernel.org>

This looks good to me. Btw in the codesearch there are about 800
uses, the majority looks like prototypes etc, so there are few actual
uses. Interestingly GLIBC still contains this:

#ifdef _LIBC
      p = __rawmemchr (p, '\0');
#else
      p = strchr (p, '\0');
#endif

The strchr (p, 0) is optimized by compilers into strlen (since that's
obviously the right optimization) so adding rawmemchr was not
only wasted effort, but it made things slower as well. So we should
remove these uses from GLIBC.

Cheers,
Wilco


More information about the Libc-alpha mailing list