This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] improve string find algorithm
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Manfred <mx2927 at gmail dot com>
- Cc: libstdc++ at gcc dot gnu dot org, Aditya K <hiraditya at msn dot com>, Aditya Kumar <aditya dot k7 at samsung dot com>, Sebastian Pop <sebpop at gmail dot com>
- Date: Tue, 10 Jan 2017 17:37:55 +0000
- Subject: Re: [PATCH] improve string find algorithm
- Authentication-results: sourceware.org; auth=none
- References: <1481132816-31162-1-git-send-email-aditya.k7@samsung.com> <CGME20170106133507epcas2p15eaabe5ca279349c9f3603a6c2bb61d8@epcas2p1.samsung.com> <20170106133502.GB2966@redhat.com> <016101d2682b$136dc890$3a4959b0$@samsung.com> <20170106202058.GH2966@redhat.com> <a2f93eec-d72d-96e2-5736-23ee8f35b709@gmail.com>
On 10/01/17 17:12 +0100, Manfred wrote:
On 1/6/2017 9:20 PM, Jonathan Wakely wrote:
+ // Compare the full strings from the first occurrence of __elem0.
+ // We already know that __first[0] == __s[0] but compare them again
+ // anyway because __s is probably aligned, which helps memcmp.
+ if (traits_type::compare(__first, __s, __n) == 0)
+ return __first - __data;
I am not sure if __s being aligned really helps here, given that
__first in principle is not. Would it be worth testing the performance
with traits_type::compare running from 1-after __s and __first?
Yes, it's probably worth checking. I assume Aditya or Sebastian did
verify that, because there's a comment in their libc++ patch about it,
but we might get diffeernt results with GCC, or with GNU libc.