Skip to content

Commit 2b60b6d

Browse files
authored
[llvm][mustache] Avoid extra allocations in parseSection (#159199)
We don't need to have extra allocations when concatenating raw bodies.
1 parent 4209e41 commit 2b60b6d

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
@@ -599,9 +599,16 @@ void Parser::parseSection(ASTNode *Parent, ASTNode::Type Ty,
599599
size_t Start = CurrentPtr;
600600
parseMustache(CurrentNode);
601601
const size_t End = CurrentPtr - 1;
602+
603+
size_t RawBodySize = 0;
604+
for (size_t I = Start; I < End; ++I)
605+
RawBodySize += Tokens[I].RawBody.size();
606+
602607
SmallString<128> RawBody;
603-
for (std::size_t I = Start; I < End; I++)
608+
RawBody.reserve(RawBodySize);
609+
for (std::size_t I = Start; I < End; ++I)
604610
RawBody += Tokens[I].RawBody;
611+
605612
CurrentNode->setRawBody(Ctx.Saver.save(StringRef(RawBody)));
606613
Parent->addChild(CurrentNode);
607614
}

0 commit comments

Comments
 (0)