Skip to content

Commit f02a68a

Browse files
committed
fixed performance regression in endsWith()
1 parent cfef803 commit f02a68a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

simplecpp.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ static unsigned long long stringToULL(const std::string &s)
154154

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

160163
static bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)

0 commit comments

Comments
 (0)