diff options
author | Paul Kirth <paulkirth@google.com> | 2025-09-16 09:40:04 -0700 |
---|---|---|
committer | Paul Kirth <paulkirth@google.com> | 2025-09-25 18:52:04 -0700 |
commit | f37d1808f041d597657e3938e2cc23fd498e548f (patch) | |
tree | 73a3efdc6b352f3f2b1dd210da08d2e9ccf47d1f | |
parent | 28deddc80945faf39cf6db64452f201737b5fd05 (diff) | |
download | llvm-users/ilovepi/mustache-parse-section-opt.zip llvm-users/ilovepi/mustache-parse-section-opt.tar.gz llvm-users/ilovepi/mustache-parse-section-opt.tar.bz2 |
[llvm][mustache] Avoid extra allocations in parseSectionusers/ilovepi/mustache-parse-section-opt
We don't need to have extra allocations when concatenating raw bodies.
-rw-r--r-- | llvm/lib/Support/Mustache.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index 888104c..bb6b557 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -590,9 +590,16 @@ void Parser::parseSection(ASTNode *Parent, ASTNode::Type Ty, size_t Start = CurrentPtr; parseMustache(CurrentNode); const size_t End = CurrentPtr - 1; + + size_t RawBodySize = 0; + for (size_t I = Start; I < End; ++I) + RawBodySize += Tokens[I].RawBody.size(); + SmallString<128> RawBody; - for (std::size_t I = Start; I < End; I++) + RawBody.reserve(RawBodySize); + for (std::size_t I = Start; I < End; ++I) RawBody += Tokens[I].RawBody; + CurrentNode->setRawBody(Ctx.Saver.save(StringRef(RawBody))); Parent->addChild(CurrentNode); } |