about summary refs log tree commit diff
path: root/string
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-02-02 13:44:13 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-02-06 16:19:35 -0300
commit167f6230af97690985ccbc9b3026a7c32ec2d6e9 (patch)
tree0b3bc532d9b3f61d4cddb3fe5b2797261f83dae2 /string
parent9d4fa7a1ca9154e814b7ede8d48186832bdbebe6 (diff)
downloadglibc-167f6230af97690985ccbc9b3026a7c32ec2d6e9.tar.gz
glibc-167f6230af97690985ccbc9b3026a7c32ec2d6e9.tar.xz
glibc-167f6230af97690985ccbc9b3026a7c32ec2d6e9.zip
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).
Diffstat (limited to 'string')
-rw-r--r--string/strrchr.c18
1 files changed, 1 insertions, 17 deletions
diff --git a/string/strrchr.c b/string/strrchr.c
index 3c6e715d3b..7b76dea4e0 100644
--- a/string/strrchr.c
+++ b/string/strrchr.c
@@ -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