From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31524 invoked by alias); 24 Oct 2014 15:56:29 -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 31509 invoked by uid 89); 24 Oct 2014 15:56:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com From: "Wilco Dijkstra" To: Cc: References: In-Reply-To: Subject: RE: [PATCH] Improve performance of strncpy Date: Fri, 24 Oct 2014 15:56:00 -0000 Message-ID: <001a01cfefa3$0fb21330$2f163990$@com> MIME-Version: 1.0 X-MC-Unique: 114102416562502201 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2014-10/txt/msg00572.txt.bz2 Ping (there was some further discussion but I don't see an OK for this patc= h) > -----Original Message----- > From: Wilco Dijkstra [mailto:wdijkstr@arm.com] > Sent: 10 September 2014 16:22 > To: 'azanella@linux.vnet.ibm.com' > Cc: 'libc-alpha@sourceware.org' > Subject: RE: [PATCH] Improve performance of strncpy >=20 > Adhemerval Zanella wrote: > > Hi, the patch looks ok. I also pushed a similar modification for powerp= c based on same idea. >=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 > > I wonder if this test is really worth, my opinion is just to keep it si= mple > > and just call memset on both 'goto' in loop and after 'last_chars'. >=20 > Yes, you're right, I timed it and there is actually little difference, wh= ile > the code is now even simpler. New version below (not attaching results in= bad > characters due to various mail servers changing line endings). >=20 > OK for commit? >=20 > --- > string/strncpy.c | 14 +++++--------- > 1 file changed, 5 insertions(+), 9 deletions(-) >=20 > diff --git a/string/strncpy.c b/string/strncpy.c > index 0915e03..d5fa5be 100644 > --- a/string/strncpy.c > +++ b/string/strncpy.c > @@ -57,10 +57,10 @@ STRNCPY (char *s1, const char *s2, size_t n) > if (--n4 =3D=3D 0) > goto last_chars; > } > - n =3D n - (s1 - s) - 1; > - if (n =3D=3D 0) > - return s; > - goto zero_fill; > + s1++; > + n =3D n - (s1 - s); > + memset (s1, '\0', n); > + return s; > } >=20 > last_chars: > @@ -77,11 +77,7 @@ STRNCPY (char *s1, const char *s2, size_t n) > } > while (c !=3D '\0'); >=20 > - zero_fill: > - do > - *++s1 =3D '\0'; > - while (--n > 0); > - > + memset (s1 + 1, '\0', n); > return s; > } > libc_hidden_builtin_def (strncpy) > -- > 1.7.9.5