This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 1/*] Optimize memccpy.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Wed, 4 Sep 2013 02:03:59 +0200
- Subject: [PATCH 1/*] Optimize memccpy.
- Authentication-results: sourceware.org; auth=none
This series of patches will fix fact that nobody so far read benchmark
results. I will do superficial reading of
vim benchtest*.out
and see what problems will be uncovered.
bcopy* was ok.
Next one is memccpy which is around 20 times slower than stupid memccpy:
stupid_memccpy simple_memccpy memccpy
...
Length 512, n 1024, char 7, alignment 0/ 0: 34 896 896
Length 2048, n 1024, char 7, alignment 0/ 0: 98 1772 1772
Length 512, n 1024, char 7, alignment 1/ 6: 31 1014 1014
Length 2048, n 1024, char 7, alignment 1/ 6: 104 2014 2017
We fix could this by using stupid memccpy.
* string/memccpy.c: Use stupid memccpy.
---
string/memccpy.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/string/memccpy.c b/string/memccpy.c
index 2a33032..b158758 100644
--- a/string/memccpy.c
+++ b/string/memccpy.c
@@ -30,15 +30,12 @@ __memccpy (dest, src, c, n)
int c;
size_t n;
{
- const char *s = src;
- char *d = dest;
- const char x = c;
- size_t i = n;
+ void *p = memchr (src, c, n);
- while (i-- > 0)
- if ((*d++ = *s++) == x)
- return d;
+ if (p != NULL)
+ return mempcpy (dest, src, p - src + 1);
+ memcpy (dest, src, n);
return NULL;
}
--
1.8.3.2