about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilco Dijkstra <wdijkstr@arm.com>2015-08-05 15:24:06 +0100
committerWilco Dijkstra <wdijkstr@arm.com>2015-08-05 16:24:03 +0100
commitf29ac72effae859140bb0d7fffdb1e6cef0ffed0 (patch)
tree8f21084d089aa7048842421dcaac965299a8d10b
parentf6482cf29d3094ca9688be59802353014c528959 (diff)
downloadglibc-f29ac72effae859140bb0d7fffdb1e6cef0ffed0.tar.gz
glibc-f29ac72effae859140bb0d7fffdb1e6cef0ffed0.tar.xz
glibc-f29ac72effae859140bb0d7fffdb1e6cef0ffed0.zip
Improve memccpy performance by using memchr/memcpy/mempcpy rather than
a byte loop. Overall performance on bench-memccpy is > 2x faster when
using the C implementation of memchr and an optimized memcpy.
-rw-r--r--ChangeLog5
-rw-r--r--string/memccpy.c11
2 files changed, 9 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 5f40e4e015..65592c3e80 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2015-08-05  Wilco Dijkstra  <wdijkstr@arm.com>
 
+	* string/memccpy.c (memccpy):
+	Improve performance by using memchr/memcpy/__mempcpy.
+
+2015-08-05  Wilco Dijkstra  <wdijkstr@arm.com>
+
 	* string/strncpy.c (strncpy):
 	Improve performance by using __strnlen/memcpy.
 
diff --git a/string/memccpy.c b/string/memccpy.c
index d9ed6975ef..0987c84aa0 100644
--- a/string/memccpy.c
+++ b/string/memccpy.c
@@ -26,15 +26,12 @@
 void *
 __memccpy (void *dest, const void *src, 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;
 }