Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/include/llvm/Support/SpecialCaseList.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ class SpecialCaseList {
std::vector<GlobMatcher::Glob> Globs;

RadixTree<iterator_range<StringRef::const_iterator>,
SmallVector<const GlobMatcher::Glob *, 1>>
PrefixToGlob;
RadixTree<iterator_range<StringRef::const_reverse_iterator>,
SmallVector<const GlobMatcher::Glob *, 1>>>
PrefixSuffixToGlob;
};

/// Represents a set of patterns and their line numbers
Expand Down
26 changes: 15 additions & 11 deletions llvm/lib/Support/SpecialCaseList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,29 @@ void SpecialCaseList::GlobMatcher::preprocess(bool BySize) {

for (const auto &G : reverse(Globs)) {
StringRef Prefix = G.Pattern.prefix();
StringRef Suffix = G.Pattern.suffix();

auto &V = PrefixToGlob.emplace(Prefix).first->second;
auto &SToGlob = PrefixSuffixToGlob.emplace(Prefix).first->second;
auto &V = SToGlob.emplace(reverse(Suffix)).first->second;
V.emplace_back(&G);
}
}

void SpecialCaseList::GlobMatcher::match(
StringRef Query,
llvm::function_ref<void(StringRef Rule, unsigned LineNo)> Cb) const {
if (!PrefixToGlob.empty()) {
for (const auto &[_, V] : PrefixToGlob.find_prefixes(Query)) {
for (const auto *G : V) {
if (G->Pattern.match(Query)) {
Cb(G->Name, G->LineNo);
// As soon as we find a match in the vector, we can break for this
// vector, since the globs are already sorted by priority within the
// prefix group. However, we continue searching other prefix groups in
// the map, as they may contain a better match overall.
break;
if (!PrefixSuffixToGlob.empty()) {
for (const auto &[_, SToGlob] : PrefixSuffixToGlob.find_prefixes(Query)) {
for (const auto &[_, V] : SToGlob.find_prefixes(reverse(Query))) {
for (const auto *G : V) {
if (G->Pattern.match(Query)) {
Cb(G->Name, G->LineNo);
// As soon as we find a match in the vector, we can break for this
// vector, since the globs are already sorted by priority within the
// prefix group. However, we continue searching other prefix groups
// in the map, as they may contain a better match overall.
break;
}
}
}
}
Expand Down