1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

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.
This commit is contained in:
Wilco Dijkstra
2015-08-05 15:24:06 +01:00
parent f6482cf29d
commit f29ac72eff
2 changed files with 9 additions and 7 deletions

View File

@ -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;
}