[llvm] [Support] Use range-based for loops (NFC) (PR #140401)
via llvm-commits
llvm-commits at lists.llvm.org
Sat May 17 13:47:49 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/140401.diff
2 Files Affected:
- (modified) llvm/include/llvm/Support/Allocator.h (+3-3)
- (modified) llvm/lib/Support/CommandLine.cpp (+13-13)
``````````diff
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/140401
More information about the llvm-commits
mailing list