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]

Re: [PATCH 1/*] Optimize memccpy.


On Wed, Sep 18, 2013 at 03:05:05PM -0700, Roland McGrath wrote:
> name space violation

ok, here is v2.

	* string/memccpy.c: Use implementation from
	benchtests/bench-memccpy.c

---
 string/memccpy.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/string/memccpy.c b/string/memccpy.c
index 2a33032..e1fca70 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]