Skip to content

Commit f37d180

Browse files
committed
[llvm][mustache] Avoid extra allocations in parseSection
We don't need to have extra allocations when concatenating raw bodies.
1 parent 28deddc commit f37d180

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

llvm/lib/Support/Mustache.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,16 @@ void Parser::parseSection(ASTNode *Parent, ASTNode::Type Ty,
590590
size_t Start = CurrentPtr;
591591
parseMustache(CurrentNode);
592592
const size_t End = CurrentPtr - 1;
593+
594+
size_t RawBodySize = 0;
595+
for (size_t I = Start; I < End; ++I)
596+
RawBodySize += Tokens[I].RawBody.size();
597+
593598
SmallString<128> RawBody;
594-
for (std::size_t I = Start; I < End; I++)
599+
RawBody.reserve(RawBodySize);
600+
for (std::size_t I = Start; I < End; ++I)
595601
RawBody += Tokens[I].RawBody;
602+
596603
CurrentNode->setRawBody(Ctx.Saver.save(StringRef(RawBody)));
597604
Parent->addChild(CurrentNode);
598605
}

0 commit comments

Comments
 (0)