[PATCH] improve string find algorithm

Jakub Jelinek jakub@redhat.com
Fri Jan 6 15:09:00 GMT 2017


On Fri, Jan 06, 2017 at 08:42:15AM -0600, Aditya Kumar wrote:
> Yes, we do.
> Sorry for the mistake, it happened because I first wrote this for
> libcxx (https://reviews.llvm.org/D27068) and while porting that line
> got missed.

Shouldn't find at least in the case where it is narrow char string
just use C library memmem?  That implements a Two-Way searching algorithm
with some improvements from Boyer-Moore.
Otherwise, consider what even your modified version will do for

#include <string>
int main() {
 (std::string(10000000, 'a')+"b").find(std::string(1000000, 'a')+"b");
}

Or does the C++ library need to reinvent everything implemented in the C
library?

	Jakub



More information about the Libstdc++ mailing list