Improve memccpy performance
Commit Message
> Wilco Dijkstra wrote:
> > Richard Earnshaw wrote:
> > On 14/01/15 18:14, Roland McGrath wrote:
> > >> + return memcpy (dest, src, n) + n;
> > >
> > > Use __mempcpy here.
> > >
> > That will be worse if mempcpy just calls memcpy; which is what the C
> > library implementation does.
>
> If GLIBC inlines mempcpy like I proposed then it would be reasonable
> to use mempcpy here as it results in exactly the same code.
So, OK for trunk with __mempcpy like below?
---
string/memccpy.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
@@ -26,15 +26,15 @@
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)
+ {
+ n = p - src + 1;
+ return __mempcpy (dest, src, n);
+ }
+ memcpy (dest, src, n);
return NULL;
}