[clang-format] Reserve vectors when the number of items is known beforehand. NFC.
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Thu, 3 Feb 2022 09:37:58 +0000 (10:37 +0100)
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Thu, 3 Feb 2022 09:38:23 +0000 (10:38 +0100)
clang/lib/Format/FormatToken.cpp
clang/lib/Format/TokenAnalyzer.cpp

index 59d6f29..40aa8f5 100644 (file)
@@ -186,6 +186,9 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
   // The lengths of an item if it is put at the end of the line. This includes
   // trailing comments which are otherwise ignored for column alignment.
   SmallVector<unsigned, 8> EndOfLineItemLength;
+  MustBreakBeforeItem.reserve(Commas.size() + 1);
+  EndOfLineItemLength.reserve(Commas.size() + 1);
+  ItemLengths.reserve(Commas.size() + 1);
 
   bool HasSeparatingComment = false;
   for (unsigned i = 0, e = Commas.size() + 1; i != e; ++i) {
index 348da1f..0a775c0 100644 (file)
@@ -116,6 +116,7 @@ std::pair<tooling::Replacements, unsigned> TokenAnalyzer::process() {
     const auto &Lines = UnwrappedLines[Run];
     LLVM_DEBUG(llvm::dbgs() << "Run " << Run << "...\n");
     SmallVector<AnnotatedLine *, 16> AnnotatedLines;
+    AnnotatedLines.reserve(Lines.size());
 
     TokenAnnotator Annotator(Style, Lex.getKeywords());
     for (const UnwrappedLine &Line : Lines) {