Skip to content

[Support] Use range-based for loops (NFC) #140401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented May 17, 2025

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

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 --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.

@kazutakahirata kazutakahirata merged commit bc6107a into llvm:main May 18, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_range_for_llvm_Support branch May 18, 2025 00:01
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants