[clang-format] Use range-for loops. NFC.

Reviewed By: MyDeveloperDay, owenpan

Differential Revision: https://reviews.llvm.org/D116795
This commit is contained in:
Marek Kurdej 2022-01-07 09:55:04 +01:00
parent f50cfc44d6
commit 01f355fe95
4 changed files with 17 additions and 31 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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];

View File

@ -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();