From patchwork Thu Aug 7 13:27:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco X-Patchwork-Id: 377861 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 32A96140076 for ; Thu, 7 Aug 2014 23:28:16 +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=HLBZ/ULYegWeX4Fpls6GRYV+PR/5/ icombkD41XZHv5iP5DWx/LOzVNLrHZnPToQrOLOyPhmQdWP7b+P1ZkqbuHYxB5xG 1FK+N7rBZH9zThSsfUWNFm1QzZNPngCI+zEtUJfjJt81vubdbrPjDDwooEFVSGig aYsM2jPHFE9L7s= 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=T/lh0y8JeK5x9Gov51RAmemHiA4=; b=mAZ dhDVvZSZO3X+wpZL37Eyoe4JmJ6AXT3wl1fDzH6vnlNZ6MV1AsFCkBztBNu0C2BX d1TKPTN1rn264eOC3Bq5nlu4YeSp4od57rpX24vxI1KzKpMMGfBLMOuXo1vgh9h8 M93UVtZJGcrQKWqWvsYjO56775TYbpiEMQtdUZRA= Received: (qmail 12455 invoked by alias); 7 Aug 2014 13:28:11 -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 12401 invoked by uid 89); 7 Aug 2014 13:28:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_05, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com From: "Wilco Dijkstra" To: Subject: [PATCH] Improve performance of strcat Date: Thu, 7 Aug 2014 14:27:50 +0100 Message-ID: <000101cfb243$63a5b1b0$2af11510$@com> MIME-Version: 1.0 X-MC-Unique: 114080714280510601 Hi, 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. OK for commit? ChangeLog: 2014-08-07 Wilco Dijkstra * string/strcat.c (strcat): Improve performance by using strlen/strcpy. --- string/strcat.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/string/strcat.c b/string/strcat.c index 2cbe8b3..983d115 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)