Skip to content

Commit 01f355f

Browse files
committed
[clang-format] Use range-for loops. NFC.
Reviewed By: MyDeveloperDay, owenpan Differential Revision: https://reviews.llvm.org/D116795
1 parent f50cfc4 commit 01f355f

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

clang/lib/Format/AffectedRangeManager.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,10 @@ bool AffectedRangeManager::computeAffectedLines(
5959

6060
bool AffectedRangeManager::affectsCharSourceRange(
6161
const CharSourceRange &Range) {
62-
for (SmallVectorImpl<CharSourceRange>::const_iterator I = Ranges.begin(),
63-
E = Ranges.end();
64-
I != E; ++I) {
65-
if (!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(), I->getBegin()) &&
66-
!SourceMgr.isBeforeInTranslationUnit(I->getEnd(), Range.getBegin()))
62+
for (const CharSourceRange &R : Ranges)
63+
if (!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(), R.getBegin()) &&
64+
!SourceMgr.isBeforeInTranslationUnit(R.getEnd(), Range.getBegin()))
6765
return true;
68-
}
6966
return false;
7067
}
7168

clang/lib/Format/FormatToken.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,11 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
296296
const CommaSeparatedList::ColumnFormat *
297297
CommaSeparatedList::getColumnFormat(unsigned RemainingCharacters) const {
298298
const ColumnFormat *BestFormat = nullptr;
299-
for (SmallVector<ColumnFormat, 4>::const_reverse_iterator
300-
I = Formats.rbegin(),
301-
E = Formats.rend();
302-
I != E; ++I) {
303-
if (I->TotalWidth <= RemainingCharacters || I->Columns == 1) {
304-
if (BestFormat && I->LineCount > BestFormat->LineCount)
299+
for (const ColumnFormat &Format : llvm::reverse(Formats)) {
300+
if (Format.TotalWidth <= RemainingCharacters || Format.Columns == 1) {
301+
if (BestFormat && Format.LineCount > BestFormat->LineCount)
305302
break;
306-
BestFormat = &*I;
303+
BestFormat = &Format;
307304
}
308305
}
309306
return BestFormat;

clang/lib/Format/TokenAnalyzer.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,8 @@ std::pair<tooling::Replacements, unsigned> TokenAnalyzer::process() {
127127

128128
LLVM_DEBUG({
129129
llvm::dbgs() << "Replacements for run " << Run << ":\n";
130-
for (tooling::Replacements::const_iterator I = RunResult.first.begin(),
131-
E = RunResult.first.end();
132-
I != E; ++I) {
133-
llvm::dbgs() << I->toString() << "\n";
134-
}
130+
for (const tooling::Replacement &Replacement : RunResult.first)
131+
llvm::dbgs() << Replacement.toString() << "\n";
135132
});
136133
for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
137134
delete AnnotatedLines[i];

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,9 @@ void UnwrappedLineParser::parse() {
343343
pushToken(FormatTok);
344344
addUnwrappedLine();
345345

346-
for (SmallVectorImpl<UnwrappedLine>::iterator I = Lines.begin(),
347-
E = Lines.end();
348-
I != E; ++I) {
349-
Callback.consumeUnwrappedLine(*I);
350-
}
346+
for (const UnwrappedLine &Line : Lines)
347+
Callback.consumeUnwrappedLine(Line);
348+
351349
Callback.finishRun();
352350
Lines.clear();
353351
while (!PPLevelBranchIndex.empty() &&
@@ -3269,10 +3267,7 @@ continuesLineCommentSection(const FormatToken &FormatTok,
32693267

32703268
void UnwrappedLineParser::flushComments(bool NewlineBeforeNext) {
32713269
bool JustComments = Line->Tokens.empty();
3272-
for (SmallVectorImpl<FormatToken *>::const_iterator
3273-
I = CommentsBeforeNextToken.begin(),
3274-
E = CommentsBeforeNextToken.end();
3275-
I != E; ++I) {
3270+
for (FormatToken *Tok : CommentsBeforeNextToken) {
32763271
// Line comments that belong to the same line comment section are put on the
32773272
// same line since later we might want to reflow content between them.
32783273
// Additional fine-grained breaking of line comment sections is controlled
@@ -3281,11 +3276,11 @@ void UnwrappedLineParser::flushComments(bool NewlineBeforeNext) {
32813276
//
32823277
// FIXME: Consider putting separate line comment sections as children to the
32833278
// unwrapped line instead.
3284-
(*I)->ContinuesLineCommentSection =
3285-
continuesLineCommentSection(**I, *Line, CommentPragmasRegex);
3286-
if (isOnNewLine(**I) && JustComments && !(*I)->ContinuesLineCommentSection)
3279+
Tok->ContinuesLineCommentSection =
3280+
continuesLineCommentSection(*Tok, *Line, CommentPragmasRegex);
3281+
if (isOnNewLine(*Tok) && JustComments && !Tok->ContinuesLineCommentSection)
32873282
addUnwrappedLine();
3288-
pushToken(*I);
3283+
pushToken(Tok);
32893284
}
32903285
if (NewlineBeforeNext && JustComments)
32913286
addUnwrappedLine();

0 commit comments

Comments
 (0)