@@ -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 {
256239 friend class SpecialCaseList ;
257- void preprocess (bool OrderBySize );
240+ void preprocess ();
258241 const Matcher *findMatcher (StringRef Prefix, StringRef Category) const ;
259242
260243public:
@@ -315,17 +298,17 @@ bool SpecialCaseList::createInternal(const std::vector<std::string> &Paths,
315298 return false ;
316299 }
317300 std::string ParseError;
318- if (!parse (i, FileOrErr.get ().get (), ParseError, /* OrderBySize= */ false )) {
301+ if (!parse (i, FileOrErr.get ().get (), ParseError)) {
319302 Error = (Twine (" error parsing file '" ) + Path + " ': " + ParseError).str ();
320303 return false ;
321304 }
322305 }
323306 return true ;
324307}
325308
326- bool SpecialCaseList::createInternal (const MemoryBuffer *MB, std::string &Error,
327- bool OrderBySize ) {
328- if (!parse (0 , MB, Error, OrderBySize ))
309+ bool SpecialCaseList::createInternal (const MemoryBuffer *MB,
310+ std::string &Error ) {
311+ if (!parse (0 , MB, Error))
329312 return false ;
330313 return true ;
331314}
@@ -352,7 +335,7 @@ SpecialCaseList::addSection(StringRef SectionStr, unsigned FileNo,
352335}
353336
354337bool SpecialCaseList::parse (unsigned FileIdx, const MemoryBuffer *MB,
355- std::string &Error, bool OrderBySize ) {
338+ std::string &Error) {
356339 unsigned long long Version = 2 ;
357340
358341 StringRef Header = MB->getBuffer ();
@@ -428,7 +411,7 @@ bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB,
428411 }
429412
430413 for (Section &S : Sections)
431- S.Impl ->preprocess (OrderBySize );
414+ S.Impl ->preprocess ();
432415
433416 return true ;
434417}
@@ -479,29 +462,21 @@ SpecialCaseList::Section::SectionImpl::findMatcher(StringRef Prefix,
479462 return &II->second ;
480463}
481464
482- void SpecialCaseList::Section::SectionImpl::preprocess (bool OrderBySize ) {
483- SectionMatcher.preprocess (false );
465+ void SpecialCaseList::Section::SectionImpl::preprocess () {
466+ SectionMatcher.preprocess ();
484467 for (auto &[K1, E] : Entries)
485468 for (auto &[K2, M] : E)
486- M.preprocess (OrderBySize );
469+ M.preprocess ();
487470}
488471
489472unsigned SpecialCaseList::Section::getLastMatch (StringRef Prefix,
490473 StringRef Query,
491474 StringRef Category) const {
492475 if (const Matcher *M = Impl->findMatcher (Prefix, Category))
493- return M->match (Query). second ;
476+ return M->match (Query);
494477 return 0 ;
495478}
496479
497- StringRef SpecialCaseList::Section::getLongestMatch (StringRef Prefix,
498- StringRef Query,
499- StringRef Category) const {
500- if (const Matcher *M = Impl->findMatcher (Prefix, Category))
501- return M->match (Query).first ;
502- return {};
503- }
504-
505480bool SpecialCaseList::Section::hasPrefix (StringRef Prefix) const {
506481 return Impl->Entries .find (Prefix) != Impl->Entries .end ();
507482}
0 commit comments