From patchwork Wed Aug 20 12:44:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 2453 Received: (qmail 4905 invoked by alias); 20 Aug 2014 12:44:25 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 4884 invoked by uid 89); 20 Aug 2014 12:44:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com From: "Wilco Dijkstra" To: Subject: [PATCH] Improve performance of strncat Date: Wed, 20 Aug 2014 13:44:05 +0100 Message-ID: <000001cfbc74$6dbf1020$493d3060$@com> MIME-Version: 1.0 X-MC-Unique: 114082013441900801 Hi, 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: 2014-08-20 Wilco Dijkstra * string/strncat.c (strncat): Improve performance by using strlen. --- string/strncat.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/string/strncat.c b/string/strncat.c index 7ac4456..6d29114 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) {