@@ -38,16 +38,13 @@ namespace llvm {
3838
3939namespace {
4040
41- using Match = std::pair<StringRef, unsigned >;
42- static constexpr Match NotMatched = {" " , 0 };
43-
4441// Lagacy v1 matcher.
4542class RegexMatcher {
4643public:
4744 Error insert (StringRef Pattern, unsigned LineNumber);
48- void preprocess (bool BySize );
45+ void preprocess ();
4946
50- Match match (StringRef Query) const ;
47+ unsigned match (StringRef Query) const ;
5148
5249 struct Reg {
5350 Reg (StringRef Name, unsigned LineNo, Regex &&Rg)
@@ -63,9 +60,9 @@ class RegexMatcher {
6360class GlobMatcher {
6461public:
6562 Error insert (StringRef Pattern, unsigned LineNumber);
66- void preprocess (bool BySize );
63+ void preprocess ();
6764
68- Match match (StringRef Query) const ;
65+ unsigned match (StringRef Query) const ;
6966
7067 struct Glob {
7168 Glob (StringRef Name, unsigned LineNo, GlobPattern &&Pattern)
@@ -92,10 +89,10 @@ class Matcher {
9289 Matcher (bool UseGlobs, bool RemoveDotSlash);
9390
9491 Error insert (StringRef Pattern, unsigned LineNumber);
95- void preprocess (bool BySize );
96- Match match (StringRef Query) const ;
92+ void preprocess ();
93+ unsigned match (StringRef Query) const ;
9794
98- bool matchAny (StringRef Query) const { return match (Query). second > 0 ; }
95+ bool matchAny (StringRef Query) const { return match (Query); }
9996
10097 std::variant<RegexMatcher, GlobMatcher> M;
10198 bool RemoveDotSlash;
@@ -125,19 +122,13 @@ Error RegexMatcher::insert(StringRef Pattern, unsigned LineNumber) {
125122 return Error::success ();
126123}
127124
128- void RegexMatcher::preprocess (bool BySize) {
129- if (BySize) {
130- llvm::stable_sort (RegExes, [](const Reg &A, const Reg &B) {
131- return A.Name .size () < B.Name .size ();
132- });
133- }
134- }
125+ void RegexMatcher::preprocess () {}
135126
136- Match RegexMatcher::match (StringRef Query) const {
127+ unsigned RegexMatcher::match (StringRef Query) const {
137128 for (const auto &R : reverse (RegExes))
138129 if (R.Rg .match (Query))
139- return {R. Name , R. LineNo } ;
140- return NotMatched ;
130+ return R. LineNo ;
131+ return 0 ;
141132}
142133
143134Error GlobMatcher::insert (StringRef Pattern, unsigned LineNumber) {
@@ -151,13 +142,7 @@ Error GlobMatcher::insert(StringRef Pattern, unsigned LineNumber) {
151142 return Error::success ();
152143}
153144
154- void GlobMatcher::preprocess (bool BySize) {
155- if (BySize) {
156- llvm::stable_sort (Globs, [](const Glob &A, const Glob &B) {
157- return A.Name .size () < B.Name .size ();
158- });
159- }
160-
145+ void GlobMatcher::preprocess () {
161146 for (const auto &[Idx, G] : enumerate(Globs)) {
162147 StringRef Prefix = G.Pattern .prefix ();
163148 StringRef Suffix = G.Pattern .suffix ();
@@ -181,7 +166,7 @@ void GlobMatcher::preprocess(bool BySize) {
181166 }
182167}
183168
184- Match GlobMatcher::match (StringRef Query) const {
169+ unsigned GlobMatcher::match (StringRef Query) const {
185170 int Best = -1 ;
186171 if (!PrefixSuffixToGlob.empty ()) {
187172 for (const auto &[_, SToGlob] : PrefixSuffixToGlob.find_prefixes (Query)) {
@@ -224,9 +209,7 @@ Match GlobMatcher::match(StringRef Query) const {
224209 }
225210 }
226211 }
227- if (Best < 0 )
228- return NotMatched;
229- return {Globs[Best].Name , Globs[Best].LineNo };
212+ return Best < 0 ? 0 : Globs[Best].LineNo ;
230213}
231214
232215Matcher::Matcher (bool UseGlobs, bool RemoveDotSlash)
@@ -241,20 +224,20 @@ Error Matcher::insert(StringRef Pattern, unsigned LineNumber) {
241224 return std::visit ([&](auto &V) { return V.insert (Pattern, LineNumber); }, M);
242225}
243226
244- void Matcher::preprocess (bool BySize ) {
245- return std::visit ([&](auto &V) { return V.preprocess (BySize ); }, M);
227+ void Matcher::preprocess () {
228+ return std::visit ([&](auto &V) { return V.preprocess (); }, M);
246229}
247230
248- Match Matcher::match (StringRef Query) const {
231+ unsigned Matcher::match (StringRef Query) const {
249232 if (RemoveDotSlash)
250233 Query = llvm::sys::path::remove_leading_dotslash (Query);
251- return std::visit ([&](auto &V) -> Match { return V.match (Query); }, M);
234+ return std::visit ([&](auto &V) -> unsigned { return V.match (Query); }, M);
252235}
253236} // namespace
254237
255238class SpecialCaseList ::Section::SectionImpl {
256239public:
257- void preprocess (bool OrderBySize );
240+ void preprocess ();
258241 const Matcher *findMatcher (StringRef Prefix, StringRef Category) const ;
259242
260243 using SectionEntries = StringMap<StringMap<Matcher>>;
@@ -304,17 +287,17 @@ bool SpecialCaseList::createInternal(const std::vector<std::string> &Paths,
304287 return false ;
305288 }
306289 std::string ParseError;
307- if (!parse (i, FileOrErr.get ().get (), ParseError, /* OrderBySize= */ false )) {
290+ if (!parse (i, FileOrErr.get ().get (), ParseError)) {
308291 Error = (Twine (" error parsing file '" ) + Path + " ': " + ParseError).str ();
309292 return false ;
310293 }
311294 }
312295 return true ;
313296}
314297
315- bool SpecialCaseList::createInternal (const MemoryBuffer *MB, std::string &Error,
316- bool OrderBySize ) {
317- if (!parse (0 , MB, Error, OrderBySize ))
298+ bool SpecialCaseList::createInternal (const MemoryBuffer *MB,
299+ std::string &Error ) {
300+ if (!parse (0 , MB, Error))
318301 return false ;
319302 return true ;
320303}
@@ -337,7 +320,7 @@ SpecialCaseList::addSection(StringRef SectionStr, unsigned FileNo,
337320}
338321
339322bool SpecialCaseList::parse (unsigned FileIdx, const MemoryBuffer *MB,
340- std::string &Error, bool OrderBySize ) {
323+ std::string &Error) {
341324 unsigned long long Version = 2 ;
342325
343326 StringRef Header = MB->getBuffer ();
@@ -413,7 +396,7 @@ bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB,
413396 }
414397
415398 for (Section &S : Sections)
416- S.Impl ->preprocess (OrderBySize );
399+ S.Impl ->preprocess ();
417400
418401 return true ;
419402}
@@ -465,29 +448,21 @@ SpecialCaseList::Section::SectionImpl::findMatcher(StringRef Prefix,
465448 return &II->second ;
466449}
467450
468- void SpecialCaseList::Section::SectionImpl::preprocess (bool OrderBySize ) {
469- SectionMatcher.preprocess (false );
451+ void SpecialCaseList::Section::SectionImpl::preprocess () {
452+ SectionMatcher.preprocess ();
470453 for (auto &[K1, E] : Entries)
471454 for (auto &[K2, M] : E)
472- M.preprocess (OrderBySize );
455+ M.preprocess ();
473456}
474457
475458unsigned SpecialCaseList::Section::getLastMatch (StringRef Prefix,
476459 StringRef Query,
477460 StringRef Category) const {
478461 if (const Matcher *M = Impl->findMatcher (Prefix, Category))
479- return M->match (Query). second ;
462+ return M->match (Query);
480463 return 0 ;
481464}
482465
483- StringRef SpecialCaseList::Section::getLongestMatch (StringRef Prefix,
484- StringRef Query,
485- StringRef Category) const {
486- if (const Matcher *M = Impl->findMatcher (Prefix, Category))
487- return M->match (Query).first ;
488- return {};
489- }
490-
491466bool SpecialCaseList::Section::hasPrefix (StringRef Prefix) const {
492467 return Impl->Entries .find (Prefix) != Impl->Entries .end ();
493468}
0 commit comments