Skip to content

Commit

Permalink
[clang-format] Reserve vectors when the number of items is known befo…
Browse files Browse the repository at this point in the history
…rehand. NFC.
  • Loading branch information
mkurdej committed Feb 3, 2022
1 parent ee4ba9f commit 768a619
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/Format/FormatToken.cpp
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Format/TokenAnalyzer.cpp
Expand Up @@ -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) {
Expand Down

0 comments on commit 768a619

Please sign in to comment.