From patchwork Fri Feb 27 15:17:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 5344 Received: (qmail 38685 invoked by alias); 27 Feb 2015 15:17:32 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 38673 invoked by uid 89); 27 Feb 2015 15:17:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com From: "Wilco Dijkstra" To: "Richard Earnshaw" , "'Roland McGrath'" Cc: References: <001f01d03004$e05abdb0$a1103910$@com> <20150114181430.C9E062C39DB@topped-with-meat.com> <54B79A67.2010208@arm.com> In-Reply-To: Subject: RE: [PATCH] Improve memccpy performance Date: Fri, 27 Feb 2015 15:17:18 -0000 Message-ID: <000701d052a0$79ec7910$6dc56b30$@com> MIME-Version: 1.0 X-MC-Unique: 115022715172736301 > 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; }