[llvm] 7aa9b33 - Use range based loop to iterate over OptTable::PrefixesUnion

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 16 06:14:16 PST 2022


Author: serge-sans-paille
Date: 2022-12-16T15:12:31+01:00
New Revision: 7aa9b335d63caf61bc0f2de5ace5b48008f5f509

URL: https://github.com/llvm/llvm-project/commit/7aa9b335d63caf61bc0f2de5ace5b48008f5f509
DIFF: https://github.com/llvm/llvm-project/commit/7aa9b335d63caf61bc0f2de5ace5b48008f5f509.diff

LOG: Use range based loop to iterate over OptTable::PrefixesUnion

And sneak in a small storage optimization of OptTable::PrefixChars

Added: 
    

Modified: 
    llvm/include/llvm/Option/OptTable.h
    llvm/lib/Option/OptTable.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h
index e884ebeb788c4..10d67b1b34915 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -10,6 +10,7 @@
 #define LLVM_OPTION_OPTTABLE_H
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Option/OptSpecifier.h"
@@ -74,7 +75,7 @@ class OptTable {
   /// The union of all option prefixes. If an argument does not begin with
   /// one of these, it is an input.
   StringSet<> PrefixesUnion;
-  std::string PrefixChars;
+  SmallString<8> PrefixChars;
 
 private:
   const Info &getInfo(OptSpecifier Opt) const {

diff  --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index d579e1b68b27f..786760f2c64ac 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -139,9 +139,7 @@ OptTable::OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase)
   }
 
   // Build prefix chars.
-  for (StringSet<>::const_iterator I = PrefixesUnion.begin(),
-                                   E = PrefixesUnion.end(); I != E; ++I) {
-    StringRef Prefix = I->getKey();
+  for (const StringRef &Prefix : PrefixesUnion.keys()) {
     for (char C : Prefix)
       if (!is_contained(PrefixChars, C))
         PrefixChars.push_back(C);
@@ -161,9 +159,8 @@ const Option OptTable::getOption(OptSpecifier Opt) const {
 static bool isInput(const StringSet<> &Prefixes, StringRef Arg) {
   if (Arg == "-")
     return true;
-  for (StringSet<>::const_iterator I = Prefixes.begin(),
-                                   E = Prefixes.end(); I != E; ++I)
-    if (Arg.startswith(I->getKey()))
+  for (const StringRef &Prefix : Prefixes.keys())
+    if (Arg.startswith(Prefix))
       return false;
   return true;
 }


        


More information about the llvm-commits mailing list