[clang] 01f355f - [clang-format] Use range-for loops. NFC.
Marek Kurdej via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 7 01:01:17 PST 2022
Author: Marek Kurdej
Date: 2022-01-07T10:01:09+01:00
New Revision: 01f355fe95f6b45db8bb239239b7ed978e094a13
URL: https://github.com/llvm/llvm-project/commit/01f355fe95f6b45db8bb239239b7ed978e094a13
DIFF: https://github.com/llvm/llvm-project/commit/01f355fe95f6b45db8bb239239b7ed978e094a13.diff
LOG: [clang-format] Use range-for loops. NFC.
Reviewed By: MyDeveloperDay, owenpan
Differential Revision: https://reviews.llvm.org/D116795
Added:
Modified:
clang/lib/Format/AffectedRangeManager.cpp
clang/lib/Format/FormatToken.cpp
clang/lib/Format/TokenAnalyzer.cpp
clang/lib/Format/UnwrappedLineParser.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/AffectedRangeManager.cpp b/clang/lib/Format/AffectedRangeManager.cpp
index 7ad1f7070d0a..3b735c4e6859 100644
--- a/clang/lib/Format/AffectedRangeManager.cpp
+++ b/clang/lib/Format/AffectedRangeManager.cpp
@@ -59,13 +59,10 @@ bool AffectedRangeManager::computeAffectedLines(
bool AffectedRangeManager::affectsCharSourceRange(
const CharSourceRange &Range) {
- for (SmallVectorImpl<CharSourceRange>::const_iterator I = Ranges.begin(),
- E = Ranges.end();
- I != E; ++I) {
- if (!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(), I->getBegin()) &&
- !SourceMgr.isBeforeInTranslationUnit(I->getEnd(), Range.getBegin()))
+ for (const CharSourceRange &R : Ranges)
+ if (!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(), R.getBegin()) &&
+ !SourceMgr.isBeforeInTranslationUnit(R.getEnd(), Range.getBegin()))
return true;
- }
return false;
}
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 57f8a5a45cbb..def5663d0449 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -296,14 +296,11 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
const CommaSeparatedList::ColumnFormat *
CommaSeparatedList::getColumnFormat(unsigned RemainingCharacters) const {
const ColumnFormat *BestFormat = nullptr;
- for (SmallVector<ColumnFormat, 4>::const_reverse_iterator
- I = Formats.rbegin(),
- E = Formats.rend();
- I != E; ++I) {
- if (I->TotalWidth <= RemainingCharacters || I->Columns == 1) {
- if (BestFormat && I->LineCount > BestFormat->LineCount)
+ for (const ColumnFormat &Format : llvm::reverse(Formats)) {
+ if (Format.TotalWidth <= RemainingCharacters || Format.Columns == 1) {
+ if (BestFormat && Format.LineCount > BestFormat->LineCount)
break;
- BestFormat = &*I;
+ BestFormat = &Format;
}
}
return BestFormat;
diff --git a/clang/lib/Format/TokenAnalyzer.cpp b/clang/lib/Format/TokenAnalyzer.cpp
index d83e837ca134..3f7722093175 100644
--- a/clang/lib/Format/TokenAnalyzer.cpp
+++ b/clang/lib/Format/TokenAnalyzer.cpp
@@ -127,11 +127,8 @@ std::pair<tooling::Replacements, unsigned> TokenAnalyzer::process() {
LLVM_DEBUG({
llvm::dbgs() << "Replacements for run " << Run << ":\n";
- for (tooling::Replacements::const_iterator I = RunResult.first.begin(),
- E = RunResult.first.end();
- I != E; ++I) {
- llvm::dbgs() << I->toString() << "\n";
- }
+ for (const tooling::Replacement &Replacement : RunResult.first)
+ llvm::dbgs() << Replacement.toString() << "\n";
});
for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
delete AnnotatedLines[i];
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 17187b7996aa..410b0557c4cd 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -343,11 +343,9 @@ void UnwrappedLineParser::parse() {
pushToken(FormatTok);
addUnwrappedLine();
- for (SmallVectorImpl<UnwrappedLine>::iterator I = Lines.begin(),
- E = Lines.end();
- I != E; ++I) {
- Callback.consumeUnwrappedLine(*I);
- }
+ for (const UnwrappedLine &Line : Lines)
+ Callback.consumeUnwrappedLine(Line);
+
Callback.finishRun();
Lines.clear();
while (!PPLevelBranchIndex.empty() &&
@@ -3269,10 +3267,7 @@ continuesLineCommentSection(const FormatToken &FormatTok,
void UnwrappedLineParser::flushComments(bool NewlineBeforeNext) {
bool JustComments = Line->Tokens.empty();
- for (SmallVectorImpl<FormatToken *>::const_iterator
- I = CommentsBeforeNextToken.begin(),
- E = CommentsBeforeNextToken.end();
- I != E; ++I) {
+ for (FormatToken *Tok : CommentsBeforeNextToken) {
// Line comments that belong to the same line comment section are put on the
// same line since later we might want to reflow content between them.
// Additional fine-grained breaking of line comment sections is controlled
@@ -3281,11 +3276,11 @@ void UnwrappedLineParser::flushComments(bool NewlineBeforeNext) {
//
// FIXME: Consider putting separate line comment sections as children to the
// unwrapped line instead.
- (*I)->ContinuesLineCommentSection =
- continuesLineCommentSection(**I, *Line, CommentPragmasRegex);
- if (isOnNewLine(**I) && JustComments && !(*I)->ContinuesLineCommentSection)
+ Tok->ContinuesLineCommentSection =
+ continuesLineCommentSection(*Tok, *Line, CommentPragmasRegex);
+ if (isOnNewLine(*Tok) && JustComments && !Tok->ContinuesLineCommentSection)
addUnwrappedLine();
- pushToken(*I);
+ pushToken(Tok);
}
if (NewlineBeforeNext && JustComments)
addUnwrappedLine();
More information about the cfe-commits
mailing list