This patch improves strncat performance by using strlen. Strlen has a fast C implemen...
authorWilco Dijkstra <wdijkstr@arm.com>
Fri, 24 Oct 2014 16:12:12 +0000 (16:12 +0000)
committerWilco Dijkstra <wdijkstr@arm.com>
Fri, 24 Oct 2014 16:12:12 +0000 (16:12 +0000)
this
will improve performance even on targets which don't have an optimized strlen. It is about twice
as
fast as the original strncat in bench-strncat.

ChangeLog
string/strncat.c

index f73c55e..40e294b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2014-10-24  Wilco Dijkstra  <wdijkstr@arm.com>
 
+       * string/strncat.c (strncat): Improve performance by using strlen.
+
+2014-10-24  Wilco Dijkstra  <wdijkstr@arm.com>
+
        * string/strcat.c (strcat): Improve performance by using strlen/strcpy.
 
 2014-10-24  Wilco Dijkstra  <wdijkstr@arm.com>
index 7ac4456..6d29114 100644 (file)
@@ -33,13 +33,11 @@ STRNCAT (char *s1, const char *s2, size_t n)
   char *s = s1;
 
   /* Find the end of S1.  */
-  do
-    c = *s1++;
-  while (c != '\0');
+  s1 += strlen (s1);
 
   /* Make S1 point before next character, so we can increment
      it while memory is read (wins on pipelined cpus).  */
-  s1 -= 2;
+  s1 -= 1;
 
   if (n >= 4)
     {