This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/*] Optimize memccpy.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]