Skip to content

Commit 04610b9

Browse files
authored
[clang-format][NFC] Replace SmallVectorImpl with ArrayRef (#121621)
1 parent 66f16e6 commit 04610b9

File tree

7 files changed

+48
-54
lines changed

7 files changed

+48
-54
lines changed

clang/lib/Format/AffectedRangeManager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ namespace format {
2121

2222
bool AffectedRangeManager::computeAffectedLines(
2323
SmallVectorImpl<AnnotatedLine *> &Lines) {
24-
SmallVectorImpl<AnnotatedLine *>::iterator I = Lines.begin();
25-
SmallVectorImpl<AnnotatedLine *>::iterator E = Lines.end();
24+
ArrayRef<AnnotatedLine *>::iterator I = Lines.begin();
25+
ArrayRef<AnnotatedLine *>::iterator E = Lines.end();
2626
bool SomeLineAffected = false;
2727
const AnnotatedLine *PreviousLine = nullptr;
2828
while (I != E) {
@@ -34,7 +34,7 @@ bool AffectedRangeManager::computeAffectedLines(
3434
// if any token within the directive is affected.
3535
if (Line->InPPDirective) {
3636
FormatToken *Last = Line->Last;
37-
SmallVectorImpl<AnnotatedLine *>::iterator PPEnd = I + 1;
37+
const auto *PPEnd = I + 1;
3838
while (PPEnd != E && !(*PPEnd)->First->HasUnescapedNewline) {
3939
Last = (*PPEnd)->Last;
4040
++PPEnd;
@@ -89,8 +89,8 @@ bool AffectedRangeManager::affectsLeadingEmptyLines(const FormatToken &Tok) {
8989
}
9090

9191
void AffectedRangeManager::markAllAsAffected(
92-
SmallVectorImpl<AnnotatedLine *>::iterator I,
93-
SmallVectorImpl<AnnotatedLine *>::iterator E) {
92+
ArrayRef<AnnotatedLine *>::iterator I,
93+
ArrayRef<AnnotatedLine *>::iterator E) {
9494
while (I != E) {
9595
(*I)->Affected = true;
9696
markAllAsAffected((*I)->Children.begin(), (*I)->Children.end());

clang/lib/Format/AffectedRangeManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class AffectedRangeManager {
4747
bool affectsLeadingEmptyLines(const FormatToken &Tok);
4848

4949
// Marks all lines between I and E as well as all their children as affected.
50-
void markAllAsAffected(SmallVectorImpl<AnnotatedLine *>::iterator I,
51-
SmallVectorImpl<AnnotatedLine *>::iterator E);
50+
void markAllAsAffected(ArrayRef<AnnotatedLine *>::iterator I,
51+
ArrayRef<AnnotatedLine *>::iterator E);
5252

5353
// Determines whether 'Line' is affected by the SourceRanges given as input.
5454
// Returns \c true if line or one if its children is affected.

clang/lib/Format/Format.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3085,8 +3085,8 @@ static bool affectsRange(ArrayRef<tooling::Range> Ranges, unsigned Start,
30853085
// its current line.
30863086
// If `Cursor` is not on any #include, `Index` will be UINT_MAX.
30873087
static std::pair<unsigned, unsigned>
3088-
FindCursorIndex(const SmallVectorImpl<IncludeDirective> &Includes,
3089-
const SmallVectorImpl<unsigned> &Indices, unsigned Cursor) {
3088+
FindCursorIndex(const ArrayRef<IncludeDirective> &Includes,
3089+
const ArrayRef<unsigned> &Indices, unsigned Cursor) {
30903090
unsigned CursorIndex = UINT_MAX;
30913091
unsigned OffsetToEOL = 0;
30923092
for (int i = 0, e = Includes.size(); i != e; ++i) {
@@ -3135,7 +3135,7 @@ std::string replaceCRLF(const std::string &Code) {
31353135
// provided and put on a deleted #include, it will be moved to the remaining
31363136
// #include in the duplicate #includes.
31373137
static void sortCppIncludes(const FormatStyle &Style,
3138-
const SmallVectorImpl<IncludeDirective> &Includes,
3138+
const ArrayRef<IncludeDirective> &Includes,
31393139
ArrayRef<tooling::Range> Ranges, StringRef FileName,
31403140
StringRef Code, tooling::Replacements &Replaces,
31413141
unsigned *Cursor) {
@@ -3378,7 +3378,7 @@ static unsigned findJavaImportGroup(const FormatStyle &Style,
33783378
// import group, a newline is inserted, and within each import group, a
33793379
// lexicographic sort based on ASCII value is performed.
33803380
static void sortJavaImports(const FormatStyle &Style,
3381-
const SmallVectorImpl<JavaImportDirective> &Imports,
3381+
const ArrayRef<JavaImportDirective> &Imports,
33823382
ArrayRef<tooling::Range> Ranges, StringRef FileName,
33833383
StringRef Code, tooling::Replacements &Replaces) {
33843384
unsigned ImportsBeginOffset = Imports.front().Offset;

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,7 @@ bool FormatTokenLexer::tryMergeTokens(ArrayRef<tok::TokenKind> Kinds,
564564
if (Tokens.size() < Kinds.size())
565565
return false;
566566

567-
SmallVectorImpl<FormatToken *>::const_iterator First =
568-
Tokens.end() - Kinds.size();
567+
const auto *First = Tokens.end() - Kinds.size();
569568
for (unsigned i = 0; i < Kinds.size(); ++i)
570569
if (First[i]->isNot(Kinds[i]))
571570
return false;
@@ -577,7 +576,7 @@ bool FormatTokenLexer::tryMergeTokens(size_t Count, TokenType NewType) {
577576
if (Tokens.size() < Count)
578577
return false;
579578

580-
SmallVectorImpl<FormatToken *>::const_iterator First = Tokens.end() - Count;
579+
const auto *First = Tokens.end() - Count;
581580
unsigned AddLength = 0;
582581
for (size_t i = 1; i < Count; ++i) {
583582
// If there is whitespace separating the token and the previous one,

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ class LevelIndentTracker {
183183
unsigned Indent = 0;
184184
};
185185

186-
const FormatToken *getMatchingNamespaceToken(
187-
const AnnotatedLine *Line,
188-
const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
186+
const FormatToken *
187+
getMatchingNamespaceToken(const AnnotatedLine *Line,
188+
const ArrayRef<AnnotatedLine *> &AnnotatedLines) {
189189
if (!Line->startsWith(tok::r_brace))
190190
return nullptr;
191191
size_t StartLineIndex = Line->MatchingOpeningBlockLineIndex;
@@ -200,9 +200,9 @@ StringRef getNamespaceTokenText(const AnnotatedLine *Line) {
200200
return NamespaceToken ? NamespaceToken->TokenText : StringRef();
201201
}
202202

203-
StringRef getMatchingNamespaceTokenText(
204-
const AnnotatedLine *Line,
205-
const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
203+
StringRef
204+
getMatchingNamespaceTokenText(const AnnotatedLine *Line,
205+
const ArrayRef<AnnotatedLine *> &AnnotatedLines) {
206206
const FormatToken *NamespaceToken =
207207
getMatchingNamespaceToken(Line, AnnotatedLines);
208208
return NamespaceToken ? NamespaceToken->TokenText : StringRef();
@@ -241,8 +241,8 @@ class LineJoiner {
241241
/// Calculates how many lines can be merged into 1 starting at \p I.
242242
unsigned
243243
tryFitMultipleLinesInOne(LevelIndentTracker &IndentTracker,
244-
SmallVectorImpl<AnnotatedLine *>::const_iterator I,
245-
SmallVectorImpl<AnnotatedLine *>::const_iterator E) {
244+
ArrayRef<AnnotatedLine *>::const_iterator I,
245+
ArrayRef<AnnotatedLine *>::const_iterator E) {
246246
const unsigned Indent = IndentTracker.getIndent();
247247

248248
// Can't join the last line with anything.
@@ -614,8 +614,8 @@ class LineJoiner {
614614
}
615615

616616
unsigned
617-
tryMergeSimplePPDirective(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
618-
SmallVectorImpl<AnnotatedLine *>::const_iterator E,
617+
tryMergeSimplePPDirective(ArrayRef<AnnotatedLine *>::const_iterator I,
618+
ArrayRef<AnnotatedLine *>::const_iterator E,
619619
unsigned Limit) {
620620
if (Limit == 0)
621621
return 0;
@@ -626,8 +626,8 @@ class LineJoiner {
626626
return 1;
627627
}
628628

629-
unsigned tryMergeNamespace(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
630-
SmallVectorImpl<AnnotatedLine *>::const_iterator E,
629+
unsigned tryMergeNamespace(ArrayRef<AnnotatedLine *>::const_iterator I,
630+
ArrayRef<AnnotatedLine *>::const_iterator E,
631631
unsigned Limit) {
632632
if (Limit == 0)
633633
return 0;
@@ -692,9 +692,10 @@ class LineJoiner {
692692
return 2;
693693
}
694694

695-
unsigned tryMergeSimpleControlStatement(
696-
SmallVectorImpl<AnnotatedLine *>::const_iterator I,
697-
SmallVectorImpl<AnnotatedLine *>::const_iterator E, unsigned Limit) {
695+
unsigned
696+
tryMergeSimpleControlStatement(ArrayRef<AnnotatedLine *>::const_iterator I,
697+
ArrayRef<AnnotatedLine *>::const_iterator E,
698+
unsigned Limit) {
698699
if (Limit == 0)
699700
return 0;
700701
if (Style.BraceWrapping.AfterControlStatement ==
@@ -734,10 +735,9 @@ class LineJoiner {
734735
return 1;
735736
}
736737

737-
unsigned
738-
tryMergeShortCaseLabels(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
739-
SmallVectorImpl<AnnotatedLine *>::const_iterator E,
740-
unsigned Limit) {
738+
unsigned tryMergeShortCaseLabels(ArrayRef<AnnotatedLine *>::const_iterator I,
739+
ArrayRef<AnnotatedLine *>::const_iterator E,
740+
unsigned Limit) {
741741
if (Limit == 0 || I + 1 == E ||
742742
I[1]->First->isOneOf(tok::kw_case, tok::kw_default)) {
743743
return 0;
@@ -768,7 +768,7 @@ class LineJoiner {
768768
if (Line->First->is(tok::comment)) {
769769
if (Level != Line->Level)
770770
return 0;
771-
SmallVectorImpl<AnnotatedLine *>::const_iterator J = I + 2 + NumStmts;
771+
const auto *J = I + 2 + NumStmts;
772772
for (; J != E; ++J) {
773773
Line = *J;
774774
if (Line->InPPDirective != InPPDirective)
@@ -789,10 +789,9 @@ class LineJoiner {
789789
return NumStmts;
790790
}
791791

792-
unsigned
793-
tryMergeSimpleBlock(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
794-
SmallVectorImpl<AnnotatedLine *>::const_iterator E,
795-
unsigned Limit) {
792+
unsigned tryMergeSimpleBlock(ArrayRef<AnnotatedLine *>::const_iterator I,
793+
ArrayRef<AnnotatedLine *>::const_iterator E,
794+
unsigned Limit) {
796795
// Don't merge with a preprocessor directive.
797796
if (I[1]->Type == LT_PreprocessorDirective)
798797
return 0;
@@ -974,26 +973,25 @@ class LineJoiner {
974973

975974
/// Returns the modified column limit for \p I if it is inside a macro and
976975
/// needs a trailing '\'.
977-
unsigned
978-
limitConsideringMacros(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
979-
SmallVectorImpl<AnnotatedLine *>::const_iterator E,
980-
unsigned Limit) {
976+
unsigned limitConsideringMacros(ArrayRef<AnnotatedLine *>::const_iterator I,
977+
ArrayRef<AnnotatedLine *>::const_iterator E,
978+
unsigned Limit) {
981979
if (I[0]->InPPDirective && I + 1 != E &&
982980
!I[1]->First->HasUnescapedNewline && I[1]->First->isNot(tok::eof)) {
983981
return Limit < 2 ? 0 : Limit - 2;
984982
}
985983
return Limit;
986984
}
987985

988-
bool nextTwoLinesFitInto(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
986+
bool nextTwoLinesFitInto(ArrayRef<AnnotatedLine *>::const_iterator I,
989987
unsigned Limit) {
990988
if (I[1]->First->MustBreakBefore || I[2]->First->MustBreakBefore)
991989
return false;
992990
return 1 + I[1]->Last->TotalLength + 1 + I[2]->Last->TotalLength <= Limit;
993991
}
994992

995-
bool nextNLinesFitInto(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
996-
SmallVectorImpl<AnnotatedLine *>::const_iterator E,
993+
bool nextNLinesFitInto(ArrayRef<AnnotatedLine *>::const_iterator I,
994+
ArrayRef<AnnotatedLine *>::const_iterator E,
997995
unsigned Limit) {
998996
unsigned JoinedLength = 0;
999997
for (const auto *J = I + 1; J != E; ++J) {
@@ -1034,9 +1032,9 @@ class LineJoiner {
10341032

10351033
const FormatStyle &Style;
10361034
const AdditionalKeywords &Keywords;
1037-
const SmallVectorImpl<AnnotatedLine *>::const_iterator End;
1035+
const ArrayRef<AnnotatedLine *>::const_iterator End;
10381036

1039-
SmallVectorImpl<AnnotatedLine *>::const_iterator Next;
1037+
ArrayRef<AnnotatedLine *>::const_iterator Next;
10401038
const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines;
10411039
};
10421040

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ void printLine(llvm::raw_ostream &OS, const UnwrappedLine &Line,
5151
<< "T=" << (unsigned)I->Tok->getType()
5252
<< ", OC=" << I->Tok->OriginalColumn << ", \"" << I->Tok->TokenText
5353
<< "\"] ";
54-
for (SmallVectorImpl<UnwrappedLine>::const_iterator
55-
CI = I->Children.begin(),
56-
CE = I->Children.end();
54+
for (const auto *CI = I->Children.begin(), *CE = I->Children.end();
5755
CI != CE; ++CI) {
5856
OS << "\n";
5957
printLine(OS, *CI, (Prefix + " ").str());
@@ -4788,8 +4786,7 @@ void UnwrappedLineParser::nextToken(int LevelDifference) {
47884786
}
47894787

47904788
void UnwrappedLineParser::distributeComments(
4791-
const SmallVectorImpl<FormatToken *> &Comments,
4792-
const FormatToken *NextTok) {
4789+
const ArrayRef<FormatToken *> &Comments, const FormatToken *NextTok) {
47934790
// Whether or not a line comment token continues a line is controlled by
47944791
// the method continuesLineCommentSection, with the following caveat:
47954792
//
@@ -5011,7 +5008,7 @@ void UnwrappedLineParser::readToken(int LevelDifference) {
50115008
namespace {
50125009
template <typename Iterator>
50135010
void pushTokens(Iterator Begin, Iterator End,
5014-
llvm::SmallVectorImpl<FormatToken *> &Into) {
5011+
SmallVectorImpl<FormatToken *> &Into) {
50155012
for (auto I = Begin; I != End; ++I) {
50165013
Into.push_back(I->Tok);
50175014
for (const auto &Child : I->Children)

clang/lib/Format/UnwrappedLineParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class UnwrappedLineParser {
228228
// NextTok specifies the next token. A null pointer NextTok is supported, and
229229
// signifies either the absence of a next token, or that the next token
230230
// shouldn't be taken into account for the analysis.
231-
void distributeComments(const SmallVectorImpl<FormatToken *> &Comments,
231+
void distributeComments(const ArrayRef<FormatToken *> &Comments,
232232
const FormatToken *NextTok);
233233

234234
// Adds the comment preceding the next token to unwrapped lines.

0 commit comments

Comments
 (0)