Skip to content

Commit f9f2c19

Browse files
committed
[NFC][Support] Remove unused getLongestMatch from SpecialCaseList
This method is not used anywhere. Remove it. Pull Request: llvm#167193
1 parent ede23f3 commit f9f2c19

File tree

2 files changed

+31
-62
lines changed

2 files changed

+31
-62
lines changed

llvm/include/llvm/Support/SpecialCaseList.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ class SpecialCaseList {
110110
// classes.
111111
LLVM_ABI bool createInternal(const std::vector<std::string> &Paths,
112112
vfs::FileSystem &VFS, std::string &Error);
113-
LLVM_ABI bool createInternal(const MemoryBuffer *MB, std::string &Error,
114-
bool OrderBySize = false);
113+
LLVM_ABI bool createInternal(const MemoryBuffer *MB, std::string &Error);
115114

116115
SpecialCaseList() = default;
117116
SpecialCaseList(SpecialCaseList const &) = delete;
@@ -137,11 +136,6 @@ class SpecialCaseList {
137136
LLVM_ABI unsigned getLastMatch(StringRef Prefix, StringRef Query,
138137
StringRef Category) const;
139138

140-
// Helper method to search by Prefix, Query, and Category. Returns
141-
// matching rule, or empty string if there is no match.
142-
LLVM_ABI StringRef getLongestMatch(StringRef Prefix, StringRef Query,
143-
StringRef Category) const;
144-
145139
/// Returns true if the section has any entries for the given prefix.
146140
LLVM_ABI bool hasPrefix(StringRef Prefix) const;
147141

@@ -166,7 +160,7 @@ class SpecialCaseList {
166160

167161
/// Parses just-constructed SpecialCaseList entries from a memory buffer.
168162
LLVM_ABI bool parse(unsigned FileIdx, const MemoryBuffer *MB,
169-
std::string &Error, bool OrderBySize);
163+
std::string &Error);
170164
};
171165

172166
} // namespace llvm

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ namespace llvm {
3838

3939
namespace {
4040

41-
using Match = std::pair<StringRef, unsigned>;
42-
static constexpr Match NotMatched = {"", 0};
43-
4441
// Lagacy v1 matcher.
4542
class RegexMatcher {
4643
public:
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 {
6360
class GlobMatcher {
6461
public:
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

143134
Error 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

232215
Matcher::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

255238
class 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

260243
public:
@@ -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

354337
bool 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

489472
unsigned 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-
505480
bool SpecialCaseList::Section::hasPrefix(StringRef Prefix) const {
506481
return Impl->Entries.find(Prefix) != Impl->Entries.end();
507482
}

0 commit comments

Comments
 (0)