Skip to content

Commit 3456d1b

Browse files
committed
[llvm][mustache] Avoid extra allocations in parseSection
We don't need to have extra allocations when concatenating raw bodies.
1 parent 7adaaa3 commit 3456d1b

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
@@ -602,9 +602,16 @@ void Parser::parseSection(ASTNode *Parent, ASTNode::Type Ty,
602602
size_t Start = CurrentPtr;
603603
parseMustache(CurrentNode);
604604
const size_t End = CurrentPtr - 1;
605+
606+
size_t RawBodySize = 0;
607+
for (size_t I = Start; I < End; ++I)
608+
RawBodySize += Tokens[I].RawBody.size();
609+
605610
SmallString<128> RawBody;
606-
for (std::size_t I = Start; I < End; I++)
611+
RawBody.reserve(RawBodySize);
612+
for (std::size_t I = Start; I < End; ++I)
607613
RawBody += Tokens[I].RawBody;
614+
608615
CurrentNode->setRawBody(Ctx.Saver.save(StringRef(RawBody)));
609616
Parent->addChild(CurrentNode);
610617
}

0 commit comments

Comments
 (0)