Skip to content

Commit

Permalink
Improve memccpy performance by using memchr/memcpy/mempcpy rather than
Browse files Browse the repository at this point in the history
a byte loop. Overall performance on bench-memccpy is > 2x faster when
using the C implementation of memchr and an optimized memcpy.
  • Loading branch information
Wilco Dijkstra committed Aug 5, 2015
1 parent f6482cf commit f29ac72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
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):
Expand Down
11 changes: 4 additions & 7 deletions string/memccpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit f29ac72

Please sign in to comment.