[clang] 768a619 - [clang-format] Reserve vectors when the number of items is known beforehand. NFC.

Marek Kurdej via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 3 01:40:49 PST 2022


Author: Marek Kurdej
Date: 2022-02-03T10:38:23+01:00
New Revision: 768a6192dfc680c0c941e713c824b9046429538d

URL: https://github.com/llvm/llvm-project/commit/768a6192dfc680c0c941e713c824b9046429538d
DIFF: https://github.com/llvm/llvm-project/commit/768a6192dfc680c0c941e713c824b9046429538d.diff

LOG: [clang-format] Reserve vectors when the number of items is known beforehand. NFC.

Added: 
    

Modified: 
    clang/lib/Format/FormatToken.cpp
    clang/lib/Format/TokenAnalyzer.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 59d6f29bb54d2..40aa8f5cacb25 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -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) {

diff  --git a/clang/lib/Format/TokenAnalyzer.cpp b/clang/lib/Format/TokenAnalyzer.cpp
index 348da1f03f299..0a775c0a87eda 100644
--- a/clang/lib/Format/TokenAnalyzer.cpp
+++ b/clang/lib/Format/TokenAnalyzer.cpp
@@ -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) {


        


More information about the cfe-commits mailing list