Improve generic stpcpy performance

Message ID 549802E5.2010702@arm.com
State Committed
Headers

Commit Message

Richard Earnshaw Dec. 22, 2014, 11:39 a.m. UTC
  I noticed while going through some benchmark results that the generic
stpcpy was substantially slower than the simple_stpcpy in the benchmark
itself.

So, similar to Wilko's recent strcpy patch, this patch uses the same
approach for stpcpy.

Note that it does not help to use mempcpy, since that returns a value
that points beyond the end of the copied data.

OK?

	* string/stpcpy.c (__stpcpy): Rewrite using strlen and memcpy.
  

Comments

Adhemerval Zanella Netto Dec. 23, 2014, 11:45 a.m. UTC | #1
On 22-12-2014 09:39, Richard Earnshaw wrote:
> I noticed while going through some benchmark results that the generic
> stpcpy was substantially slower than the simple_stpcpy in the benchmark
> itself.
>
> So, similar to Wilko's recent strcpy patch, this patch uses the same
> approach for stpcpy.
>
> Note that it does not help to use mempcpy, since that returns a value
> that points beyond the end of the copied data.
>
> OK?
>
> 	* string/stpcpy.c (__stpcpy): Rewrite using strlen and memcpy.
>
LGTM.
  
Carlos O'Donell Dec. 23, 2014, 3:49 p.m. UTC | #2
On 12/22/2014 06:39 AM, Richard Earnshaw wrote:
> I noticed while going through some benchmark results that the generic
> stpcpy was substantially slower than the simple_stpcpy in the benchmark
> itself.
> 
> So, similar to Wilko's recent strcpy patch, this patch uses the same
> approach for stpcpy.
> 
> Note that it does not help to use mempcpy, since that returns a value
> that points beyond the end of the copied data.
> 
> OK?
> 
> 	* string/stpcpy.c (__stpcpy): Rewrite using strlen and memcpy.
> 

Please check this in. Thanks for making the generic routines faster.
They will all soon depend on a fast memcpy, but that's almost expected.

Cheers,
Carlos.
  
Richard Earnshaw Dec. 23, 2014, 4:15 p.m. UTC | #3
On 23/12/14 15:49, Carlos O'Donell wrote:
> On 12/22/2014 06:39 AM, Richard Earnshaw wrote:
>> I noticed while going through some benchmark results that the generic
>> stpcpy was substantially slower than the simple_stpcpy in the benchmark
>> itself.
>>
>> So, similar to Wilko's recent strcpy patch, this patch uses the same
>> approach for stpcpy.
>>
>> Note that it does not help to use mempcpy, since that returns a value
>> that points beyond the end of the copied data.
>>
>> OK?
>>
>> 	* string/stpcpy.c (__stpcpy): Rewrite using strlen and memcpy.
>>
> 
> Please check this in. Thanks for making the generic routines faster.
> They will all soon depend on a fast memcpy, but that's almost expected.
> 
> Cheers,
> Carlos.
> 

I currently don't have a commit bit, so could someone do this for me please?

If it's OK, I'll sort out commit bits in the new year, when I'm back
from vacation.

R.
  
Paul Eggert Dec. 23, 2014, 4:58 p.m. UTC | #4
Richard Earnshaw wrote:
> I currently don't have a commit bit, so could someone do this for me please?

Done, and thanks.
  

Patch

diff --git a/string/stpcpy.c b/string/stpcpy.c
index 9185acc..fd6eb1c 100644
--- a/string/stpcpy.c
+++ b/string/stpcpy.c
@@ -35,14 +35,8 @@  __stpcpy (dest, src)
      char *dest;
      const char *src;
 {
-  char *d = dest;
-  const char *s = src;
-
-  do
-    *d++ = *s;
-  while (*s++ != '\0');
-
-  return d - 1;
+  size_t len = strlen (src);
+  return memcpy (dest, src, len + 1) + len;
 }
 #ifdef libc_hidden_def
 libc_hidden_def (__stpcpy)