jeudi 21 septembre 2017

Anything faster than std::search in this case?

I am currently searching through large blocks of text using the following code. The Haystack could be a large portion of code and needle could be a couple of letters. My profiler indicates this is the bottle neck here.

bool msearch(const std::string & Haystack, const std::string& Needle)
{
    auto it = std::search(
                          Haystack.begin(), Haystack.end(),
                          Needle.begin(),   Needle.end(),
                          [](char ch1, char ch2)
                          {
                              return ch1 == ch2;
                          }
                          );
    return (it != strHaystack.end() );
}

Any suggestions on what I can do to improve performance ?

Aucun commentaire:

Enregistrer un commentaire