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 X-Patchwork-Id: 381663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EFD9814010C for ; Wed, 20 Aug 2014 22:45:27 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=Zw1ilhigigaL4Q5INunbDZL8g6pz5 KNdgM5tskbmoY6TAcd0rAH/mXD/1cCb+bcVFHsRcC3jYo0qxBc0GyGQZHnKP5ISk Zss07jTdYWyE86bWmLbHsh13M3AvL8ymkCnYyxQCeLrwm6VRUcwExTENFkYTdCga gb5S9ti9NI0ry8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=Ka1dcDs5XNnPS+Bm5UhxFCWqZF4=; b=kw+ Yndkw8nerCQhVhXjp83/MrlbE0mevZfHVhcqoqYawuQbq4cY6ITMrY4FwslbT0UV cxALSwG44/yKDBenL2N7tWDPkLcvwqzX07lWHy7POK4BZStiEBFU2RZcZvojC3bf Hu41bfV+M1vEYKKe6DtmZxAMOzT59Un1d2QAnx3s= 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) {