This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 4/*] Generic string memchr and strnlen
- From: "Wilco Dijkstra" <wdijkstr at arm dot com>
- To: 'Ondřej Bílka' <neleai at seznam dot cz>
- Cc: "'GNU C Library'" <libc-alpha at sourceware dot org>
- Date: Fri, 24 Jul 2015 16:10:24 +0100
- Subject: [PATCH 4/*] Generic string memchr and strnlen
- Authentication-results: sourceware.org; auth=none
Getting back to this, if you don't have an optimized strnlen then
it is always better to try to use memchr (there are 14 optimized
implementations of memchr but only 6 for strnlen).
So I'd suggest changing strnlen in an independent patch as:
__strnlen (const char *str, size_t n)
{
char *ret = __memchr (str, 0, n);
return ret ? ret - str : n;
}
It also looks worthwhile to express strlen and rawmemchr as memchr
so that you only need one highly optimized function rather than many.
Deferring to more widely implemented optimized assembler functions
should result in better performance than trying to optimize these
functions in C.
Wilco