diff options
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r-- | llvm/lib/Option/OptTable.cpp | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp index 786760f..c21072b 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -62,12 +62,10 @@ static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) { if (int N = StrCmpOptionName(A.Name, B.Name)) return N < 0; - for (const char * const *APre = A.Prefixes, - * const *BPre = B.Prefixes; - *APre != nullptr && *BPre != nullptr; ++APre, ++BPre){ - if (int N = StrCmpOptionName(*APre, *BPre)) + for (size_t I = 0, K = std::min(A.Prefixes.size(), B.Prefixes.size()); I != K; + ++I) + if (int N = StrCmpOptionName(A.Prefixes[I], B.Prefixes[I])) return N < 0; - } // Names are the same, check that classes are in order; exactly one // should be joined, and it should succeed the other. @@ -131,11 +129,8 @@ OptTable::OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase) // Build prefixes. for (unsigned i = FirstSearchableIndex + 1, e = getNumOptions() + 1; i != e; ++i) { - if (const char *const *P = getInfo(i).Prefixes) { - for (; *P != nullptr; ++P) { - PrefixesUnion.insert(*P); - } - } + const auto &P = getInfo(i).Prefixes; + PrefixesUnion.insert(P.begin(), P.end()); } // Build prefix chars. @@ -168,8 +163,7 @@ static bool isInput(const StringSet<> &Prefixes, StringRef Arg) { /// \returns Matched size. 0 means no match. static unsigned matchOption(const OptTable::Info *I, StringRef Str, bool IgnoreCase) { - for (const char * const *Pre = I->Prefixes; *Pre != nullptr; ++Pre) { - StringRef Prefix(*Pre); + for (auto Prefix : I->Prefixes) { if (Str.startswith(Prefix)) { StringRef Rest = Str.substr(Prefix.size()); bool Matched = IgnoreCase ? Rest.startswith_insensitive(I->Name) @@ -183,13 +177,10 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str, // Returns true if one of the Prefixes + In.Names matches Option static bool optionMatches(const OptTable::Info &In, StringRef Option) { - if (In.Prefixes) { - StringRef InName(In.Name); - for (size_t I = 0; In.Prefixes[I]; I++) - if (Option.endswith(InName)) - if (Option.slice(0, Option.size() - InName.size()) == In.Prefixes[I]) - return true; - } + for (auto Prefix : In.Prefixes) + if (Option.endswith(In.Name)) + if (Option.slice(0, Option.size() - In.Name.size()) == Prefix) + return true; return false; } @@ -221,13 +212,13 @@ OptTable::findByPrefix(StringRef Cur, unsigned int DisableFlags) const { std::vector<std::string> Ret; for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) { const Info &In = OptionInfos[I]; - if (!In.Prefixes || (!In.HelpText && !In.GroupID)) + if (In.Prefixes.empty() || (!In.HelpText && !In.GroupID)) continue; if (In.Flags & DisableFlags) continue; - for (int I = 0; In.Prefixes[I]; I++) { - std::string S = std::string(In.Prefixes[I]) + std::string(In.Name) + "\t"; + for (auto Prefix : In.Prefixes) { + std::string S = (Prefix + In.Name + "\t").str(); if (In.HelpText) S += In.HelpText; if (StringRef(S).startswith(Cur) && S != std::string(Cur) + "\t") @@ -265,7 +256,7 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString, // * Ignore positional argument option candidates (which do not // have prefixes). - if (!CandidateInfo.Prefixes) + if (CandidateInfo.Prefixes.empty()) continue; // Now check if the candidate ends with a character commonly used when @@ -285,8 +276,7 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString, // Consider each possible prefix for each candidate to find the most // appropriate one. For example, if a user asks for "--helm", suggest // "--help" over "-help". - for (int P = 0; - const char *const CandidatePrefix = CandidateInfo.Prefixes[P]; P++) { + for (auto CandidatePrefix : CandidateInfo.Prefixes) { std::string Candidate = (CandidatePrefix + CandidateName).str(); StringRef CandidateRef = Candidate; unsigned Distance = |