From: serge-sans-paille Date: Fri, 16 Dec 2022 14:10:34 +0000 (+0100) Subject: Use range based loop to iterate over OptTable::PrefixesUnion X-Git-Tag: upstream/17.0.6~23552 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7aa9b335d63caf61bc0f2de5ace5b48008f5f509;p=platform%2Fupstream%2Fllvm.git Use range based loop to iterate over OptTable::PrefixesUnion And sneak in a small storage optimization of OptTable::PrefixChars --- diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h index e884ebe..10d67b1 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 @@ private: /// 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 d579e1b..786760f 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -139,9 +139,7 @@ OptTable::OptTable(ArrayRef 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; }