Skip to content

Commit

Permalink
fixed performance regression in endsWith()
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Nov 14, 2023
1 parent cfef803 commit f967842
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ static unsigned long long stringToULL(const std::string &s)

static bool endsWith(const std::string &s, const std::string &e)
{
// TODO: std::equal() is much faster than std::string::compare() in a benchmark
// but in our case it leads to a big performance regression
//return (s.size() >= e.size() && s.compare(s.size() - e.size(), e.size(), e) == 0);
return (s.size() >= e.size()) && std::equal(e.rbegin(), e.rend(), s.rbegin());
}

Expand Down

0 comments on commit f967842

Please sign in to comment.