Skip to content

Commit 3dbccca

Browse files
[Support] Use range-based for loops (NFC)
1 parent 6a399bf commit 3dbccca

File tree

7 files changed

+55
-81
lines changed

7 files changed

+55
-81
lines changed

llvm/lib/Support/CommandLine.cpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,10 +1538,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
15381538

15391539
ErrorParsing = true;
15401540
} else {
1541-
for (SmallVectorImpl<Option *>::iterator I = SinkOpts.begin(),
1542-
E = SinkOpts.end();
1543-
I != E; ++I)
1544-
(*I)->addOccurrence(i, "", StringRef(argv[i]));
1541+
for (Option *SinkOpt : SinkOpts)
1542+
SinkOpt->addOccurrence(i, "", StringRef(argv[i]));
15451543
}
15461544
continue;
15471545
}
@@ -2303,23 +2301,17 @@ class CategorizedHelpPrinter : public HelpPrinter {
23032301

23042302
// Collect registered option categories into vector in preparation for
23052303
// sorting.
2306-
for (auto I = GlobalParser->RegisteredOptionCategories.begin(),
2307-
E = GlobalParser->RegisteredOptionCategories.end();
2308-
I != E; ++I) {
2309-
SortedCategories.push_back(*I);
2310-
}
2304+
for (OptionCategory *Category : GlobalParser->RegisteredOptionCategories)
2305+
SortedCategories.push_back(Category);
23112306

23122307
// Sort the different option categories alphabetically.
23132308
assert(SortedCategories.size() > 0 && "No option categories registered!");
23142309
array_pod_sort(SortedCategories.begin(), SortedCategories.end(),
23152310
OptionCategoryCompare);
23162311

23172312
// Create map to empty vectors.
2318-
for (std::vector<OptionCategory *>::const_iterator
2319-
I = SortedCategories.begin(),
2320-
E = SortedCategories.end();
2321-
I != E; ++I)
2322-
CategorizedOptions[*I] = std::vector<Option *>();
2313+
for (OptionCategory *Category : SortedCategories)
2314+
CategorizedOptions[Category] = std::vector<Option *>();
23232315

23242316
// Walk through pre-sorted options and assign into categories.
23252317
// Because the options are already alphabetically sorted the
@@ -2334,23 +2326,20 @@ class CategorizedHelpPrinter : public HelpPrinter {
23342326
}
23352327

23362328
// Now do printing.
2337-
for (std::vector<OptionCategory *>::const_iterator
2338-
Category = SortedCategories.begin(),
2339-
E = SortedCategories.end();
2340-
Category != E; ++Category) {
2329+
for (OptionCategory *Category : SortedCategories) {
23412330
// Hide empty categories for --help, but show for --help-hidden.
2342-
const auto &CategoryOptions = CategorizedOptions[*Category];
2331+
const auto &CategoryOptions = CategorizedOptions[Category];
23432332
bool IsEmptyCategory = CategoryOptions.empty();
23442333
if (!ShowHidden && IsEmptyCategory)
23452334
continue;
23462335

23472336
// Print category information.
23482337
outs() << "\n";
2349-
outs() << (*Category)->getName() << ":\n";
2338+
outs() << Category->getName() << ":\n";
23502339

23512340
// Check if description is set.
2352-
if (!(*Category)->getDescription().empty())
2353-
outs() << (*Category)->getDescription() << "\n\n";
2341+
if (!Category->getDescription().empty())
2342+
outs() << Category->getDescription() << "\n\n";
23542343
else
23552344
outs() << "\n";
23562345

llvm/lib/Support/ConvertUTFWrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) {
103103
std::vector<UTF16> ByteSwapped;
104104
if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {
105105
ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
106-
for (unsigned I = 0, E = ByteSwapped.size(); I != E; ++I)
107-
ByteSwapped[I] = llvm::ByteSwap_16(ByteSwapped[I]);
106+
for (UTF16 &I : ByteSwapped)
107+
I = llvm::ByteSwap_16(I);
108108
Src = &ByteSwapped[0];
109109
SrcEnd = &ByteSwapped[ByteSwapped.size() - 1] + 1;
110110
}

llvm/lib/Support/DAGDeltaAlgorithm.cpp

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,19 @@ DAGDeltaAlgorithmImpl::DAGDeltaAlgorithmImpl(
180180
DAGDeltaAlgorithm &DDA, const changeset_ty &Changes,
181181
const std::vector<edge_ty> &Dependencies)
182182
: DDA(DDA) {
183-
for (changeset_ty::const_iterator it = Changes.begin(),
184-
ie = Changes.end(); it != ie; ++it) {
185-
Predecessors.insert(std::make_pair(*it, std::vector<change_ty>()));
186-
Successors.insert(std::make_pair(*it, std::vector<change_ty>()));
183+
for (change_ty Change : Changes) {
184+
Predecessors.insert(std::make_pair(Change, std::vector<change_ty>()));
185+
Successors.insert(std::make_pair(Change, std::vector<change_ty>()));
187186
}
188-
for (std::vector<edge_ty>::const_iterator it = Dependencies.begin(),
189-
ie = Dependencies.end(); it != ie; ++it) {
190-
Predecessors[it->second].push_back(it->first);
191-
Successors[it->first].push_back(it->second);
187+
for (const edge_ty &Dep : Dependencies) {
188+
Predecessors[Dep.second].push_back(Dep.first);
189+
Successors[Dep.first].push_back(Dep.second);
192190
}
193191

194192
// Compute the roots.
195-
for (changeset_ty::const_iterator it = Changes.begin(),
196-
ie = Changes.end(); it != ie; ++it)
197-
if (succ_begin(*it) == succ_end(*it))
198-
Roots.push_back(*it);
193+
for (change_ty Change : Changes)
194+
if (succ_begin(Change) == succ_end(Change))
195+
Roots.push_back(Change);
199196

200197
// Pre-compute the closure of the successor relation.
201198
std::vector<change_ty> Worklist(Roots.begin(), Roots.end());
@@ -213,14 +210,13 @@ DAGDeltaAlgorithmImpl::DAGDeltaAlgorithmImpl(
213210
}
214211

215212
// Invert to form the predecessor closure map.
216-
for (changeset_ty::const_iterator it = Changes.begin(),
217-
ie = Changes.end(); it != ie; ++it)
218-
PredClosure.insert(std::make_pair(*it, std::set<change_ty>()));
219-
for (changeset_ty::const_iterator it = Changes.begin(),
220-
ie = Changes.end(); it != ie; ++it)
221-
for (succ_closure_iterator_ty it2 = succ_closure_begin(*it),
222-
ie2 = succ_closure_end(*it); it2 != ie2; ++it2)
223-
PredClosure[*it2].insert(*it);
213+
for (change_ty Change : Changes)
214+
PredClosure.insert(std::make_pair(Change, std::set<change_ty>()));
215+
for (change_ty Change : Changes)
216+
for (succ_closure_iterator_ty it2 = succ_closure_begin(Change),
217+
ie2 = succ_closure_end(Change);
218+
it2 != ie2; ++it2)
219+
PredClosure[*it2].insert(Change);
224220

225221
// Dump useful debug info.
226222
LLVM_DEBUG({
@@ -256,27 +252,25 @@ DAGDeltaAlgorithmImpl::DAGDeltaAlgorithmImpl(
256252
llvm::errs() << "]\n";
257253

258254
llvm::errs() << "Predecessor Closure:\n";
259-
for (changeset_ty::const_iterator it = Changes.begin(), ie = Changes.end();
260-
it != ie; ++it) {
261-
llvm::errs() << format(" %-4d: [", *it);
262-
for (pred_closure_iterator_ty it2 = pred_closure_begin(*it),
263-
ie2 = pred_closure_end(*it);
255+
for (change_ty Change : Changes) {
256+
llvm::errs() << format(" %-4d: [", Change);
257+
for (pred_closure_iterator_ty it2 = pred_closure_begin(Change),
258+
ie2 = pred_closure_end(Change);
264259
it2 != ie2; ++it2) {
265-
if (it2 != pred_closure_begin(*it))
260+
if (it2 != pred_closure_begin(Change))
266261
llvm::errs() << ", ";
267262
llvm::errs() << *it2;
268263
}
269264
llvm::errs() << "]\n";
270265
}
271266

272267
llvm::errs() << "Successor Closure:\n";
273-
for (changeset_ty::const_iterator it = Changes.begin(), ie = Changes.end();
274-
it != ie; ++it) {
275-
llvm::errs() << format(" %-4d: [", *it);
276-
for (succ_closure_iterator_ty it2 = succ_closure_begin(*it),
277-
ie2 = succ_closure_end(*it);
268+
for (change_ty Change : Changes) {
269+
llvm::errs() << format(" %-4d: [", Change);
270+
for (succ_closure_iterator_ty it2 = succ_closure_begin(Change),
271+
ie2 = succ_closure_end(Change);
278272
it2 != ie2; ++it2) {
279-
if (it2 != succ_closure_begin(*it))
273+
if (it2 != succ_closure_begin(Change))
280274
llvm::errs() << ", ";
281275
llvm::errs() << *it2;
282276
}
@@ -291,9 +285,8 @@ bool DAGDeltaAlgorithmImpl::GetTestResult(const changeset_ty &Changes,
291285
const changeset_ty &Required) {
292286
changeset_ty Extended(Required);
293287
Extended.insert(Changes.begin(), Changes.end());
294-
for (changeset_ty::const_iterator it = Changes.begin(),
295-
ie = Changes.end(); it != ie; ++it)
296-
Extended.insert(pred_closure_begin(*it), pred_closure_end(*it));
288+
for (change_ty Change : Changes)
289+
Extended.insert(pred_closure_begin(Change), pred_closure_end(Change));
297290

298291
if (FailedTestsCache.count(Extended))
299292
return false;
@@ -340,9 +333,8 @@ DAGDeltaAlgorithmImpl::Run() {
340333
// Replace the current set with the predecssors of the minimized set of
341334
// active changes.
342335
CurrentSet.clear();
343-
for (changeset_ty::const_iterator it = CurrentMinSet.begin(),
344-
ie = CurrentMinSet.end(); it != ie; ++it)
345-
CurrentSet.insert(pred_begin(*it), pred_end(*it));
336+
for (change_ty CT : CurrentMinSet)
337+
CurrentSet.insert(pred_begin(CT), pred_end(CT));
346338

347339
// FIXME: We could enforce CurrentSet intersect Required == {} here if we
348340
// wanted to protect against cyclic graphs.

llvm/lib/Support/DeltaAlgorithm.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ DeltaAlgorithm::Delta(const changeset_ty &Changes,
5757

5858
// Otherwise, partition the sets if possible; if not we are done.
5959
changesetlist_ty SplitSets;
60-
for (changesetlist_ty::const_iterator it = Sets.begin(),
61-
ie = Sets.end(); it != ie; ++it)
62-
Split(*it, SplitSets);
60+
for (const changeset_ty &Set : Sets)
61+
Split(Set, SplitSets);
6362
if (SplitSets.size() == Sets.size())
6463
return Changes;
6564

llvm/lib/Support/Signals.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ static CallbackAndCookie CallBacksToRun[MaxSignalHandlerCallbacks];
8787

8888
// Signal-safe.
8989
void sys::RunSignalHandlers() {
90-
for (size_t I = 0; I < MaxSignalHandlerCallbacks; ++I) {
91-
auto &RunMe = CallBacksToRun[I];
90+
for (CallbackAndCookie &RunMe : CallBacksToRun) {
9291
auto Expected = CallbackAndCookie::Status::Initialized;
9392
auto Desired = CallbackAndCookie::Status::Executing;
9493
if (!RunMe.Flag.compare_exchange_strong(Expected, Desired))
@@ -103,8 +102,7 @@ void sys::RunSignalHandlers() {
103102
// Signal-safe.
104103
static void insertSignalHandler(sys::SignalHandlerCallback FnPtr,
105104
void *Cookie) {
106-
for (size_t I = 0; I < MaxSignalHandlerCallbacks; ++I) {
107-
auto &SetMe = CallBacksToRun[I];
105+
for (CallbackAndCookie &SetMe : CallBacksToRun) {
108106
auto Expected = CallbackAndCookie::Status::Empty;
109107
auto Desired = CallbackAndCookie::Status::Initializing;
110108
if (!SetMe.Flag.compare_exchange_strong(Expected, Desired))

llvm/lib/Support/SourceMgr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
292292

293293
// Convert any ranges to column ranges that only intersect the line of the
294294
// location.
295-
for (unsigned i = 0, e = Ranges.size(); i != e; ++i) {
296-
SMRange R = Ranges[i];
295+
for (SMRange R : Ranges) {
297296
if (!R.isValid())
298297
continue;
299298

llvm/lib/Support/Statistic.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,10 @@ void llvm::PrintStatistics(raw_ostream &OS) {
177177

178178
// Figure out how long the biggest Value and Name fields are.
179179
unsigned MaxDebugTypeLen = 0, MaxValLen = 0;
180-
for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i) {
181-
MaxValLen = std::max(MaxValLen,
182-
(unsigned)utostr(Stats.Stats[i]->getValue()).size());
183-
MaxDebugTypeLen = std::max(MaxDebugTypeLen,
184-
(unsigned)std::strlen(Stats.Stats[i]->getDebugType()));
180+
for (TrackingStatistic *Stat : Stats.Stats) {
181+
MaxValLen = std::max(MaxValLen, (unsigned)utostr(Stat->getValue()).size());
182+
MaxDebugTypeLen =
183+
std::max(MaxDebugTypeLen, (unsigned)std::strlen(Stat->getDebugType()));
185184
}
186185

187186
Stats.sort();
@@ -192,11 +191,9 @@ void llvm::PrintStatistics(raw_ostream &OS) {
192191
<< "===" << std::string(73, '-') << "===\n\n";
193192

194193
// Print all of the statistics.
195-
for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i)
196-
OS << format("%*u %-*s - %s\n",
197-
MaxValLen, Stats.Stats[i]->getValue(),
198-
MaxDebugTypeLen, Stats.Stats[i]->getDebugType(),
199-
Stats.Stats[i]->getDesc());
194+
for (TrackingStatistic *Stat : Stats.Stats)
195+
OS << format("%*u %-*s - %s\n", MaxValLen, Stat->getValue(),
196+
MaxDebugTypeLen, Stat->getDebugType(), Stat->getDesc());
200197

201198
OS << '\n'; // Flush the output stream.
202199
OS.flush();

0 commit comments

Comments
 (0)