Skip to content

Commit 768a619

Browse files
committed
[clang-format] Reserve vectors when the number of items is known beforehand. NFC.
1 parent ee4ba9f commit 768a619

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

clang/lib/Format/FormatToken.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
186186
// The lengths of an item if it is put at the end of the line. This includes
187187
// trailing comments which are otherwise ignored for column alignment.
188188
SmallVector<unsigned, 8> EndOfLineItemLength;
189+
MustBreakBeforeItem.reserve(Commas.size() + 1);
190+
EndOfLineItemLength.reserve(Commas.size() + 1);
191+
ItemLengths.reserve(Commas.size() + 1);
189192

190193
bool HasSeparatingComment = false;
191194
for (unsigned i = 0, e = Commas.size() + 1; i != e; ++i) {

clang/lib/Format/TokenAnalyzer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ std::pair<tooling::Replacements, unsigned> TokenAnalyzer::process() {
116116
const auto &Lines = UnwrappedLines[Run];
117117
LLVM_DEBUG(llvm::dbgs() << "Run " << Run << "...\n");
118118
SmallVector<AnnotatedLine *, 16> AnnotatedLines;
119+
AnnotatedLines.reserve(Lines.size());
119120

120121
TokenAnnotator Annotator(Style, Lex.getKeywords());
121122
for (const UnwrappedLine &Line : Lines) {

0 commit comments

Comments
 (0)