From e80514b5a87c86a92352ce526c4b9db85f2a242c Mon Sep 17 00:00:00 2001 From: Wilco Dijkstra Date: Fri, 24 Oct 2014 16:12:12 +0000 Subject: [PATCH] This patch improves strncat performance by using strlen. Strlen has a fast C implementation, so 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 | 4 ++++ string/strncat.c | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f73c55e5d4..40e294b7d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-10-24 Wilco Dijkstra + + * string/strncat.c (strncat): Improve performance by using strlen. + 2014-10-24 Wilco Dijkstra * string/strcat.c (strcat): Improve performance by using strlen/strcpy. diff --git a/string/strncat.c b/string/strncat.c index 7ac44561bd..6d29114d38 100644 --- a/string/strncat.c +++ b/string/strncat.c @@ -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) {