Skip to content

Commit 050fcea

Browse files
committed
fixed performance regression in endsWith()
1 parent e040047 commit 050fcea

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

simplecpp.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ static unsigned long long stringToULL(const std::string &s)
141141

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

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

0 commit comments

Comments
 (0)