From 3001cfa4d2a29ffa7a5f1069692f0b19c0d58e40 Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 12 Sep 2023 10:58:37 +0200 Subject: [PATCH] Fix #314 TokenList::lastLine() is slow for long lines --- simplecpp.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index 7c4a6c4d..96c9d31b 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; }