@@ -33,25 +33,26 @@ using namespace llvm::opt;
3333
3434namespace {
3535struct OptNameLess {
36- const char *StrTable;
37- ArrayRef<unsigned > PrefixesTable;
36+ const StringTable *StrTable;
37+ ArrayRef<StringTable::Offset > PrefixesTable;
3838
39- explicit OptNameLess (const char *StrTable, ArrayRef<unsigned > PrefixesTable)
40- : StrTable(StrTable), PrefixesTable(PrefixesTable) {}
39+ explicit OptNameLess (const StringTable &StrTable,
40+ ArrayRef<StringTable::Offset> PrefixesTable)
41+ : StrTable(&StrTable), PrefixesTable(PrefixesTable) {}
4142
4243#ifndef NDEBUG
4344 inline bool operator ()(const OptTable::Info &A,
4445 const OptTable::Info &B) const {
4546 if (&A == &B)
4647 return false ;
4748
48- if (int Cmp = StrCmpOptionName (A.getName (StrTable, PrefixesTable),
49- B.getName (StrTable, PrefixesTable)))
49+ if (int Cmp = StrCmpOptionName (A.getName (* StrTable, PrefixesTable),
50+ B.getName (* StrTable, PrefixesTable)))
5051 return Cmp < 0 ;
5152
5253 SmallVector<StringRef, 8 > APrefixes, BPrefixes;
53- A.appendPrefixes (StrTable, PrefixesTable, APrefixes);
54- B.appendPrefixes (StrTable, PrefixesTable, BPrefixes);
54+ A.appendPrefixes (* StrTable, PrefixesTable, APrefixes);
55+ B.appendPrefixes (* StrTable, PrefixesTable, BPrefixes);
5556
5657 if (int Cmp = StrCmpOptionPrefixes (APrefixes, BPrefixes))
5758 return Cmp < 0 ;
@@ -68,17 +69,18 @@ struct OptNameLess {
6869 // Support lower_bound between info and an option name.
6970 inline bool operator ()(const OptTable::Info &I, StringRef Name) const {
7071 // Do not fallback to case sensitive comparison.
71- return StrCmpOptionName (I.getName (StrTable, PrefixesTable), Name, false ) <
72+ return StrCmpOptionName (I.getName (* StrTable, PrefixesTable), Name, false ) <
7273 0 ;
7374 }
7475};
7576} // namespace
7677
7778OptSpecifier::OptSpecifier (const Option *Opt) : ID(Opt->getID ()) {}
7879
79- OptTable::OptTable (const char *StrTable, ArrayRef<unsigned > PrefixesTable,
80+ OptTable::OptTable (const StringTable &StrTable,
81+ ArrayRef<StringTable::Offset> PrefixesTable,
8082 ArrayRef<Info> OptionInfos, bool IgnoreCase)
81- : StrTable(StrTable), PrefixesTable(PrefixesTable),
83+ : StrTable(& StrTable), PrefixesTable(PrefixesTable),
8284 OptionInfos(OptionInfos), IgnoreCase(IgnoreCase) {
8385 // Explicitly zero initialize the error to work around a bug in array
8486 // value-initialization on MinGW with gcc 4.3.5.
@@ -151,13 +153,13 @@ static bool isInput(const ArrayRef<StringRef> &Prefixes, StringRef Arg) {
151153}
152154
153155// / \returns Matched size. 0 means no match.
154- static unsigned matchOption (const char * StrTable,
155- ArrayRef<unsigned > PrefixesTable,
156+ static unsigned matchOption (const StringTable & StrTable,
157+ ArrayRef<StringTable::Offset > PrefixesTable,
156158 const OptTable::Info *I, StringRef Str,
157159 bool IgnoreCase) {
158160 StringRef Name = I->getName (StrTable, PrefixesTable);
159- for (unsigned PrefixOffset : I->getPrefixOffsets (PrefixesTable)) {
160- StringRef Prefix = & StrTable[PrefixOffset];
161+ for (auto PrefixOffset : I->getPrefixOffsets (PrefixesTable)) {
162+ StringRef Prefix = StrTable[PrefixOffset];
161163 if (Str.starts_with (Prefix)) {
162164 StringRef Rest = Str.substr (Prefix.size ());
163165 bool Matched = IgnoreCase ? Rest.starts_with_insensitive (Name)
@@ -170,13 +172,13 @@ static unsigned matchOption(const char *StrTable,
170172}
171173
172174// Returns true if one of the Prefixes + In.Names matches Option
173- static bool optionMatches (const char * StrTable,
174- ArrayRef<unsigned > PrefixesTable,
175+ static bool optionMatches (const StringTable & StrTable,
176+ ArrayRef<StringTable::Offset > PrefixesTable,
175177 const OptTable::Info &In, StringRef Option) {
176178 StringRef Name = In.getName (StrTable, PrefixesTable);
177179 if (Option.consume_back (Name))
178- for (unsigned PrefixOffset : In.getPrefixOffsets (PrefixesTable))
179- if (Option == & StrTable[PrefixOffset])
180+ for (auto PrefixOffset : In.getPrefixOffsets (PrefixesTable))
181+ if (Option == StrTable[PrefixOffset])
180182 return true ;
181183 return false ;
182184}
@@ -189,7 +191,7 @@ OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const {
189191 // Search all options and return possible values.
190192 for (size_t I = FirstSearchableIndex, E = OptionInfos.size (); I < E; I++) {
191193 const Info &In = OptionInfos[I];
192- if (!In.Values || !optionMatches (StrTable, PrefixesTable, In, Option))
194+ if (!In.Values || !optionMatches (* StrTable, PrefixesTable, In, Option))
193195 continue ;
194196
195197 SmallVector<StringRef, 8 > Candidates;
@@ -217,9 +219,9 @@ OptTable::findByPrefix(StringRef Cur, Visibility VisibilityMask,
217219 if (In.Flags & DisableFlags)
218220 continue ;
219221
220- StringRef Name = In.getName (StrTable, PrefixesTable);
221- for (unsigned PrefixOffset : In.getPrefixOffsets (PrefixesTable)) {
222- StringRef Prefix = & StrTable[PrefixOffset];
222+ StringRef Name = In.getName (* StrTable, PrefixesTable);
223+ for (auto PrefixOffset : In.getPrefixOffsets (PrefixesTable)) {
224+ StringRef Prefix = (* StrTable) [PrefixOffset];
223225 std::string S = (Twine (Prefix) + Name + " \t " ).str ();
224226 if (In.HelpText )
225227 S += In.HelpText ;
@@ -271,7 +273,7 @@ unsigned OptTable::internalFindNearest(
271273
272274 for (const Info &CandidateInfo :
273275 ArrayRef<Info>(OptionInfos).drop_front (FirstSearchableIndex)) {
274- StringRef CandidateName = CandidateInfo.getName (StrTable, PrefixesTable);
276+ StringRef CandidateName = CandidateInfo.getName (* StrTable, PrefixesTable);
275277
276278 // We can eliminate some option prefix/name pairs as candidates right away:
277279 // * Ignore option candidates with empty names, such as "--", or names
@@ -304,9 +306,9 @@ unsigned OptTable::internalFindNearest(
304306 // Consider each possible prefix for each candidate to find the most
305307 // appropriate one. For example, if a user asks for "--helm", suggest
306308 // "--help" over "-help".
307- for (unsigned CandidatePrefixOffset :
309+ for (auto CandidatePrefixOffset :
308310 CandidateInfo.getPrefixOffsets (PrefixesTable)) {
309- StringRef CandidatePrefix = & StrTable[CandidatePrefixOffset];
311+ StringRef CandidatePrefix = (* StrTable) [CandidatePrefixOffset];
310312 // If Candidate and NormalizedName have more than 'BestDistance'
311313 // characters of difference, no need to compute the edit distance, it's
312314 // going to be greater than BestDistance. Don't bother computing Candidate
@@ -359,14 +361,14 @@ std::unique_ptr<Arg> OptTable::parseOneArgGrouped(InputArgList &Args,
359361 StringRef Name = Str.ltrim (PrefixChars);
360362 const Info *Start =
361363 std::lower_bound (OptionInfos.data () + FirstSearchableIndex, End, Name,
362- OptNameLess (StrTable, PrefixesTable));
364+ OptNameLess (* StrTable, PrefixesTable));
363365 const Info *Fallback = nullptr ;
364366 unsigned Prev = Index;
365367
366368 // Search for the option which matches Str.
367369 for (; Start != End; ++Start) {
368370 unsigned ArgSize =
369- matchOption (StrTable, PrefixesTable, Start, Str, IgnoreCase);
371+ matchOption (* StrTable, PrefixesTable, Start, Str, IgnoreCase);
370372 if (!ArgSize)
371373 continue ;
372374
@@ -449,7 +451,7 @@ std::unique_ptr<Arg> OptTable::internalParseOneArg(
449451
450452 // Search for the first next option which could be a prefix.
451453 Start =
452- std::lower_bound (Start, End, Name, OptNameLess (StrTable, PrefixesTable));
454+ std::lower_bound (Start, End, Name, OptNameLess (* StrTable, PrefixesTable));
453455
454456 // Options are stored in sorted order, with '\0' at the end of the
455457 // alphabet. Since the only options which can accept a string must
@@ -464,7 +466,7 @@ std::unique_ptr<Arg> OptTable::internalParseOneArg(
464466 // Scan for first option which is a proper prefix.
465467 for (; Start != End; ++Start)
466468 if ((ArgSize =
467- matchOption (StrTable, PrefixesTable, Start, Str, IgnoreCase)))
469+ matchOption (* StrTable, PrefixesTable, Start, Str, IgnoreCase)))
468470 break ;
469471 if (Start == End)
470472 break ;
@@ -787,15 +789,15 @@ void OptTable::internalPrintHelp(
787789 OS.flush ();
788790}
789791
790- GenericOptTable::GenericOptTable (const char * StrTable,
791- ArrayRef<unsigned > PrefixesTable,
792+ GenericOptTable::GenericOptTable (const StringTable & StrTable,
793+ ArrayRef<StringTable::Offset > PrefixesTable,
792794 ArrayRef<Info> OptionInfos, bool IgnoreCase)
793795 : OptTable(StrTable, PrefixesTable, OptionInfos, IgnoreCase) {
794796
795797 std::set<StringRef> TmpPrefixesUnion;
796798 for (auto const &Info : OptionInfos.drop_front (FirstSearchableIndex))
797- for (unsigned PrefixOffset : Info.getPrefixOffsets (PrefixesTable))
798- TmpPrefixesUnion.insert (StringRef (& StrTable[PrefixOffset]) );
799+ for (auto PrefixOffset : Info.getPrefixOffsets (PrefixesTable))
800+ TmpPrefixesUnion.insert (StrTable[PrefixOffset]);
799801 PrefixesUnion.append (TmpPrefixesUnion.begin (), TmpPrefixesUnion.end ());
800802 buildPrefixChars ();
801803}
0 commit comments