Skip to content

Commit

Permalink
Fix #314 TokenList::lastLine() is slow for long lines (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Sep 12, 2023
1 parent 42090bd commit b5d1112
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,14 +1362,18 @@ std::string simplecpp::TokenList::lastLine(int maxsize) const
if (++count > maxsize)
return "";
if (!ret.empty())
ret.insert(0, 1, ' ');
ret += ' ';
// add tokens in reverse for performance reasons
if (tok->str()[0] == '\"')
ret.insert(0, "%str%");
ret += "%rts%"; // %str%
else if (tok->number)
ret.insert(0, "%num%");
else
ret.insert(0, tok->str());
ret += "%mun%"; // %num%
else {
ret += tok->str();
std::reverse(ret.end() - tok->str().length(), ret.end());
}
}
std::reverse(ret.begin(), ret.end());
return ret;
}

Expand Down

0 comments on commit b5d1112

Please sign in to comment.