summary refs log tree commit diff
path: root/string
diff options
context:
space:
mode:
authorWilco Dijkstra <wdijkstr@arm.com>2014-10-24 16:08:42 +0000
committerWilco Dijkstra <wdijkstr@arm.com>2014-10-24 16:08:42 +0000
commit6e46de42fe1695818a410a7b86d26be8b1527524 (patch)
treecb94f4c31ba74df526bffa1b6ca0713e22a0fa53 /string
parent6a9ad2faee48c5a9befd5ad6af79df37e4ea5436 (diff)
downloadglibc-6e46de42fe1695818a410a7b86d26be8b1527524.tar.gz
glibc-6e46de42fe1695818a410a7b86d26be8b1527524.tar.xz
glibc-6e46de42fe1695818a410a7b86d26be8b1527524.zip
This patch improves strcat performance by using strlen and strcpy. Strlen has a fast C
implementation, so this improves performance even on targets which don't have an optimized
strlen and strcpy - it is 25% faster in bench-strcat. On targets which don't provide an
optimized strcat but which do have an optimized strlen and strcpy, performance gain is > 2x.
Diffstat (limited to 'string')
-rw-r--r--string/strcat.c21
1 files changed, 1 insertions, 20 deletions
diff --git a/string/strcat.c b/string/strcat.c
index 2cbe8b32da..983d115707 100644
--- a/string/strcat.c
+++ b/string/strcat.c
@@ -23,26 +23,7 @@
 char *
 strcat (char *dest, const char *src)
 {
-  char *s1 = dest;
-  const char *s2 = src;
-  char c;
-
-  /* Find the end of the string.  */
-  do
-    c = *s1++;
-  while (c != '\0');
-
-  /* Make S1 point before the next character, so we can increment
-     it while memory is read (wins on pipelined cpus).  */
-  s1 -= 2;
-
-  do
-    {
-      c = *s2++;
-      *++s1 = c;
-    }
-  while (c != '\0');
-
+  strcpy (dest + strlen (dest), src);
   return dest;
 }
 libc_hidden_builtin_def (strcat)