From b5d1112072c4dec74751fdf4d40a0dba96524770 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:21:51 +0200 Subject: [PATCH] Fix #314 TokenList::lastLine() is slow for long lines (#319) --- simplecpp.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index e98ecc61..1f572fda 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -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; }