Improve performance of strncat
Commit Message
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(-)
Comments
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
@@ -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)
{