diff options
author | eldritch horrors <pennae@lix.systems> | 2024-06-16 23:10:09 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-06-17 19:46:44 +0000 |
commit | b8f49a8eaf619df6d228f2e0f9814c4a5fa4aec5 (patch) | |
tree | 311d001ae953e0f8d750ec59a124c0a737b083f0 /src/libexpr/parser-state.hh | |
parent | dad8bc679e9f7bd97442249293138c7a2af311e4 (diff) |
libexpr: store ExprConcatStrings elements as direct vector
storing a pointer only adds an unnecessary indirection at runtime.
Change-Id: If06dd05effdf1ccb0df0873580f50c775608925d
Diffstat (limited to 'src/libexpr/parser-state.hh')
-rw-r--r-- | src/libexpr/parser-state.hh | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/libexpr/parser-state.hh b/src/libexpr/parser-state.hh index 94f10064f..468b34bd3 100644 --- a/src/libexpr/parser-state.hh +++ b/src/libexpr/parser-state.hh @@ -216,7 +216,7 @@ inline Expr * ParserState::stripIndentation(const PosIdx pos, } /* Strip spaces from each line. */ - auto * es2 = new std::vector<std::pair<PosIdx, Expr *>>; + std::vector<std::pair<PosIdx, Expr *>> es2; atStartOfLine = true; size_t curDropped = 0; size_t n = es.size(); @@ -224,7 +224,7 @@ inline Expr * ParserState::stripIndentation(const PosIdx pos, const auto trimExpr = [&] (Expr * e) { atStartOfLine = false; curDropped = 0; - es2->emplace_back(i->first, e); + es2.emplace_back(i->first, e); }; const auto trimString = [&] (const StringToken & t) { std::string s2; @@ -256,19 +256,17 @@ inline Expr * ParserState::stripIndentation(const PosIdx pos, s2 = std::string(s2, 0, p + 1); } - es2->emplace_back(i->first, new ExprString(std::move(s2))); + es2.emplace_back(i->first, new ExprString(std::move(s2))); }; for (; i != es.end(); ++i, --n) { std::visit(overloaded { trimExpr, trimString }, i->second); } /* If this is a single string, then don't do a concatenation. */ - if (es2->size() == 1 && dynamic_cast<ExprString *>((*es2)[0].second)) { - auto *const result = (*es2)[0].second; - delete es2; - return result; + if (es2.size() == 1 && dynamic_cast<ExprString *>(es2[0].second)) { + return es2[0].second; } - return new ExprConcatStrings(pos, true, es2); + return new ExprConcatStrings(pos, true, std::move(es2)); } inline PosIdx ParserState::at(const ParserLocation & loc) |