[llvm] [Support] Use range-based for loops (NFC) (PR #140401)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat May 17 13:47:13 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/140401
None
>From 251f04eed42213f20d7a66e64467ac4fbb5b10a2 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 17 May 2025 00:10:33 -0700
Subject: [PATCH] [Support] Use range-based for loops (NFC)
---
llvm/include/llvm/Support/Allocator.h | 6 +++---
llvm/lib/Support/CommandLine.cpp | 26 +++++++++++++-------------
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/llvm/include/llvm/Support/Allocator.h b/llvm/include/llvm/Support/Allocator.h
index 59934190a5206..bc0265904ef65 100644
--- a/llvm/include/llvm/Support/Allocator.h
+++ b/llvm/include/llvm/Support/Allocator.h
@@ -249,9 +249,9 @@ class BumpPtrAllocatorImpl
// Use negative index to denote custom sized slabs.
int64_t InCustomSizedSlabIdx = -1;
- for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
- const char *S = static_cast<const char *>(CustomSizedSlabs[Idx].first);
- size_t Size = CustomSizedSlabs[Idx].second;
+ for (const auto &Slab : CustomSizedSlabs) {
+ const char *S = static_cast<const char *>(Slab.first);
+ size_t Size = Slab.second;
if (P >= S && P < S + Size)
return InCustomSizedSlabIdx - static_cast<int64_t>(P - S);
InCustomSizedSlabIdx -= static_cast<int64_t>(Size);
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 49cefb10523b8..ced7e7bc8a028 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -2313,8 +2313,8 @@ class HelpPrinter {
StrSubCommandPairVector;
// Print the options. Opts is assumed to be alphabetically sorted.
virtual void printOptions(StrOptionPairVector &Opts, size_t MaxArgLen) {
- for (size_t i = 0, e = Opts.size(); i != e; ++i)
- Opts[i].second->printOptionInfo(MaxArgLen);
+ for (const auto &Opt : Opts)
+ Opt.second->printOptionInfo(MaxArgLen);
}
void printSubCommands(StrSubCommandPairVector &Subs, size_t MaxSubLen) {
@@ -2384,8 +2384,8 @@ class HelpPrinter {
if (Sub == &SubCommand::getTopLevel() && !Subs.empty()) {
// Compute the maximum subcommand length...
size_t MaxSubLen = 0;
- for (size_t i = 0, e = Subs.size(); i != e; ++i)
- MaxSubLen = std::max(MaxSubLen, strlen(Subs[i].first));
+ for (const auto &Sub : Subs)
+ MaxSubLen = std::max(MaxSubLen, strlen(Sub.first));
outs() << "\n\n";
outs() << "SUBCOMMANDS:\n\n";
@@ -2400,8 +2400,8 @@ class HelpPrinter {
// Compute the maximum argument length...
size_t MaxArgLen = 0;
- for (size_t i = 0, e = Opts.size(); i != e; ++i)
- MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
+ for (const auto &Opt : Opts)
+ MaxArgLen = std::max(MaxArgLen, Opt.second->getOptionWidth());
outs() << "OPTIONS:\n";
printOptions(Opts, MaxArgLen);
@@ -2447,9 +2447,9 @@ class CategorizedHelpPrinter : public HelpPrinter {
// Walk through pre-sorted options and assign into categories.
// Because the options are already alphabetically sorted the
// options within categories will also be alphabetically sorted.
- for (size_t I = 0, E = Opts.size(); I != E; ++I) {
- Option *Opt = Opts[I].second;
- for (auto &Cat : Opt->Categories) {
+ for (const auto &I : Opts) {
+ Option *Opt = I.second;
+ for (OptionCategory *Cat : Opt->Categories) {
assert(llvm::is_contained(SortedCategories, Cat) &&
"Option has an unregistered category");
CategorizedOptions[Cat].push_back(Opt);
@@ -2708,11 +2708,11 @@ void CommandLineParser::printOptionValues() {
// Compute the maximum argument length...
size_t MaxArgLen = 0;
- for (size_t i = 0, e = Opts.size(); i != e; ++i)
- MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
+ for (const auto &Opt : Opts)
+ MaxArgLen = std::max(MaxArgLen, Opt.second->getOptionWidth());
- for (size_t i = 0, e = Opts.size(); i != e; ++i)
- Opts[i].second->printOptionValue(MaxArgLen, CommonOptions->PrintAllOptions);
+ for (const auto &Opt : Opts)
+ Opt.second->printOptionValue(MaxArgLen, CommonOptions->PrintAllOptions);
}
// Utility function for printing the help message.
More information about the llvm-commits
mailing list