mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 12:30:06 +00:00
string: Improve generic strrchr with memrchr and strlen
Now that both strlen and memrchr have word vectorized implementation, it should be faster to implement strrchr based on memrchr over the string length instead of calling strchr on a loop. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits).
This commit is contained in:
parent
9d4fa7a1ca
commit
167f6230af
@ -27,23 +27,7 @@
|
||||
char *
|
||||
STRRCHR (const char *s, int c)
|
||||
{
|
||||
const char *found, *p;
|
||||
|
||||
c = (unsigned char) c;
|
||||
|
||||
/* Since strchr is fast, we use it rather than the obvious loop. */
|
||||
|
||||
if (c == '\0')
|
||||
return strchr (s, '\0');
|
||||
|
||||
found = NULL;
|
||||
while ((p = strchr (s, c)) != NULL)
|
||||
{
|
||||
found = p;
|
||||
s = p + 1;
|
||||
}
|
||||
|
||||
return (char *) found;
|
||||
return __memrchr (s, c, strlen (s) + 1);
|
||||
}
|
||||
|
||||
#ifdef weak_alias
|
||||
|
Loading…
Reference in New Issue
Block a user