From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5005 invoked by alias); 20 Aug 2014 12:44:26 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 4914 invoked by uid 89); 20 Aug 2014 12:44:26 -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 strncpy Date: Wed, 20 Aug 2014 12:44:00 -0000 Message-ID: <000401cfbc74$758a9b80$609fd280$@com> MIME-Version: 1.0 X-MC-Unique: 114082013442300601 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0005_01CFBC7C.D74F0380" X-SW-Source: 2014-08/txt/msg00313.txt.bz2 This is a multi-part message in MIME format. ------=_NextPart_000_0005_01CFBC7C.D74F0380 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-length: 392 Hi, This patch improves strncpy performance by using memset to clear memory aft= er the string when the buffer is much larger than the copied string. This is better as memset is s= ignificantly faster than a simple byte-loop. On bench-strncpy it is ~25% faster. ChangeLog: 2014-08-20 Wilco Dijkstra * string/strncpy.c (strncpy): Improve performance by using memset.= ------=_NextPart_000_0005_01CFBC7C.D74F0380 Content-Type: text/plain; name=Improve-performance-of-strncpy.txt Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Improve-performance-of-strncpy.txt" Content-length: 510 --- string/strncpy.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/string/strncpy.c b/string/strncpy.c index 0915e03..604417c 100644 --- a/string/strncpy.c +++ b/string/strncpy.c @@ -78,9 +78,12 @@ STRNCPY (char *s1, const char *s2, size_t n) while (c !=3D '\0'); =20 zero_fill: - do - *++s1 =3D '\0'; - while (--n > 0); + if (n >=3D 8) + memset (s1 + 1, '\0', n); + else + do + *++s1 =3D '\0'; + while (--n > 0); =20 return s; } --=20 1.7.9.5 ------=_NextPart_000_0005_01CFBC7C.D74F0380--