aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Option/OptTable.cpp
diff options
context:
space:
mode:
authorserge-sans-paille <sguelton@mozilla.com>2022-12-09 10:15:41 +0100
committerserge-sans-paille <sguelton@mozilla.com>2022-12-09 10:15:41 +0100
commitd881fdf72047fd18b88c6a65d0966cad542c95cd (patch)
tree2b45ca981a544a276fabf88023c8aff50c3041b9 /llvm/lib/Option/OptTable.cpp
parentb013ebe059d931fc30dd7283166300e7cc3a86d9 (diff)
downloadllvm-d881fdf72047fd18b88c6a65d0966cad542c95cd.zip
llvm-d881fdf72047fd18b88c6a65d0966cad542c95cd.tar.gz
llvm-d881fdf72047fd18b88c6a65d0966cad542c95cd.tar.bz2
Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"
This reverts commit 4faf00006cf989f3ae212912994022c0486a2dc4.
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r--llvm/lib/Option/OptTable.cpp35
1 files changed, 19 insertions, 16 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index f4426bc..ef4873e 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -36,10 +36,16 @@ 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 == '\0') // A is a prefix of B.
return 1;
@@ -54,7 +60,7 @@ static int StrCmpOptionNameIgnoreCase(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) {
@@ -180,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;
@@ -341,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;
@@ -397,20 +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 = 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
@@ -450,11 +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,