This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Improve memccpy performance
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Wilco Dijkstra <wdijkstr at arm dot com>
- Cc: Richard Earnshaw <Richard dot Earnshaw at arm dot com>, 'Roland McGrath' <roland at hack dot frob dot com>, libc-alpha at sourceware dot org
- Date: Tue, 12 May 2015 11:21:17 +0200
- Subject: Re: [PATCH] Improve memccpy performance
- Authentication-results: sourceware.org; auth=none
- References: <001f01d03004$e05abdb0$a1103910$ at com> <20150114181430 dot C9E062C39DB at topped-with-meat dot com> <54B79A67 dot 2010208 at arm dot com> <000301d07778$19d9f640$4d8de2c0$ at com>
On Wed, Apr 15, 2015 at 01:31:30PM +0100, Wilco Dijkstra wrote:
> ping
>
> > Wilco Dijkstra wrote:
> > > 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(-)
> >
> > diff --git a/string/memccpy.c b/string/memccpy.c
> > index 70ee2ae..d4146f9 100644
> > --- a/string/memccpy.c
> > +++ b/string/memccpy.c
> > @@ -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;
> > }
> >
> > --
> > 1.9.1
ok for me.