This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Improve performance of strncat
- From: Adhemerval Zanella <azanella at linux dot vnet dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Date: Wed, 20 Aug 2014 15:33:45 -0300
- Subject: Re: [PATCH] Improve performance of strncat
- Authentication-results: sourceware.org; auth=none
- References: <000001cfbc74$6dbf1020$493d3060$ at com>
>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.
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