diff options
author | serge-sans-paille <sguelton@mozilla.com> | 2022-12-07 17:15:14 +0100 |
---|---|---|
committer | serge-sans-paille <sguelton@mozilla.com> | 2022-12-07 17:29:53 +0100 |
commit | 40ade845be698355b230abc19c7a76b200188772 (patch) | |
tree | c7533023deea17976b9740654e3b75bb847c51ce /llvm/lib/Option/OptTable.cpp | |
parent | a2c9f12dd6acf0134e6e6d6e78d7e8ae3083cf24 (diff) | |
download | llvm-40ade845be698355b230abc19c7a76b200188772.zip llvm-40ade845be698355b230abc19c7a76b200188772.tar.gz llvm-40ade845be698355b230abc19c7a76b200188772.tar.bz2 |
Revert "Store OptTable::Info::Name as a StringRef"
Another revert, for another set of issues I don't reproduce locally...
see https://lab.llvm.org/buildbot/#/builders/139/builds/32327
This reverts commit bdfa3100dc3ea9e9ce4d3d4100ea6bb4c3fa2b81.
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r-- | llvm/lib/Option/OptTable.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp index 06ed6b7..ef4873e 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -36,23 +36,31 @@ namespace opt { // Ordering on Info. The ordering is *almost* case-insensitive lexicographic, // with an exception. '\0' comes at the end of the alphabet instead of the // beginning (thus options precede any other options which prefix them). -static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) { - size_t MinSize = std::min(A.size(), B.size()); - if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize))) - return Res; +static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) { + const char *X = A, *Y = B; + char a = tolower(*A), b = tolower(*B); + while (a == b) { + if (a == '\0') + return 0; + + a = tolower(*++X); + b = tolower(*++Y); + } - if (A.size() == B.size()) - return 0; + if (a == '\0') // A is a prefix of B. + return 1; + if (b == '\0') // B is a prefix of A. + return -1; - return (A.size() == MinSize) ? 1 /* A is a prefix of B. */ - : -1 /* B is a prefix of A */; + // Otherwise lexicographic. + return (a < b) ? -1 : 1; } #ifndef NDEBUG -static int StrCmpOptionName(StringRef A, StringRef B) { +static int StrCmpOptionName(const char *A, const char *B) { if (int N = StrCmpOptionNameIgnoreCase(A, B)) return N; - return A.compare(B); + return strcmp(A, B); } static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) { @@ -78,7 +86,7 @@ static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) { #endif // Support lower_bound between info and an option name. -static inline bool operator<(const OptTable::Info &I, StringRef Name) { +static inline bool operator<(const OptTable::Info &I, const char *Name) { return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0; } @@ -178,7 +186,7 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str, bool Matched = IgnoreCase ? Rest.startswith_insensitive(I->Name) : Rest.startswith(I->Name); if (Matched) - return Prefix.size() + I->Name.size(); + return Prefix.size() + StringRef(I->Name).size(); } } return 0; @@ -313,7 +321,7 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString, return BestDistance; } -bool OptTable::addValues(StringRef Option, const char *Values) { +bool OptTable::addValues(const char *Option, const char *Values) { for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) { Info &In = OptionInfos[I]; if (optionMatches(In, Option)) { @@ -339,8 +347,8 @@ std::unique_ptr<Arg> OptTable::parseOneArgGrouped(InputArgList &Args, const Info *End = OptionInfos.data() + OptionInfos.size(); StringRef Name = Str.ltrim(PrefixChars); - const Info *Start = - std::lower_bound(OptionInfos.data() + FirstSearchableIndex, End, Name); + const Info *Start = std::lower_bound( + OptionInfos.data() + FirstSearchableIndex, End, Name.data()); const Info *Fallback = nullptr; unsigned Prev = Index; @@ -395,19 +403,19 @@ std::unique_ptr<Arg> OptTable::ParseOneArg(const ArgList &Args, unsigned &Index, unsigned FlagsToInclude, unsigned FlagsToExclude) const { unsigned Prev = Index; - StringRef Str = Args.getArgString(Index); + const char *Str = Args.getArgString(Index); // Anything that doesn't start with PrefixesUnion is an input, as is '-' // itself. if (isInput(PrefixesUnion, Str)) - return std::make_unique<Arg>(getOption(InputOptionID), Str, Index++, Str.data()); + return std::make_unique<Arg>(getOption(InputOptionID), Str, Index++, Str); const Info *Start = OptionInfos.data() + FirstSearchableIndex; const Info *End = OptionInfos.data() + OptionInfos.size(); - StringRef Name = Str.ltrim(PrefixChars); + StringRef Name = StringRef(Str).ltrim(PrefixChars); // Search for the first next option which could be a prefix. - Start = std::lower_bound(Start, End, Name); + Start = std::lower_bound(Start, End, Name.data()); // Options are stored in sorted order, with '\0' at the end of the // alphabet. Since the only options which can accept a string must @@ -447,9 +455,9 @@ std::unique_ptr<Arg> OptTable::ParseOneArg(const ArgList &Args, unsigned &Index, // If we failed to find an option and this arg started with /, then it's // probably an input path. if (Str[0] == '/') - return std::make_unique<Arg>(getOption(InputOptionID), Str, Index++, Str.data()); + return std::make_unique<Arg>(getOption(InputOptionID), Str, Index++, Str); - return std::make_unique<Arg>(getOption(UnknownOptionID), Str, Index++, Str.data()); + return std::make_unique<Arg>(getOption(UnknownOptionID), Str, Index++, Str); } InputArgList OptTable::ParseArgs(ArrayRef<const char *> ArgArr, |