This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
RE: [PATCH] Improve performance of strncat
- From: "Wilco Dijkstra" <wdijkstr at arm dot com>
- To: <azanella at linux dot vnet dot ibm dot com>
- Cc: <libc-alpha at sourceware dot org>
- Date: Wed, 10 Sep 2014 16:27:49 +0100
- Subject: RE: [PATCH] Improve performance of strncat
- Authentication-results: sourceware.org; auth=none
- References:
> Adhemerval Zanella wrote:
>From what is worth, this is similar optimization I pushed for powerpc
>(which some more arch-specific tunings) and looks ok.
>
>PS: try to send patch as inline instead of attachments.
I can for small changes but due to Outlook there will always be some bad
characters in it...
I assume this is OK for commit now the code freeze is over, unless there
are further comments in 48 hours.
Wilco
On 20-08-2014 09:44, Wilco Dijkstra wrote:
> 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 <wdijkstr@arm.com>
>
> * 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
> @@ -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)
> {
> -- 1.7.9.5