Improve generic stpcpy performance
Richard Earnshaw
rearnsha@arm.com
Mon Dec 22 11:39:00 GMT 2014
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.
-------------- next part --------------
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)
More information about the Libc-alpha
mailing list