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
4 changes: 4 additions & 0 deletions llvm/include/llvm/Support/SpecialCaseList.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class SpecialCaseList {
RadixTree<iterator_range<StringRef::const_reverse_iterator>,
SmallVector<const GlobMatcher::Glob *, 1>>>
PrefixSuffixToGlob;

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

/// Represents a set of patterns and their line numbers
Expand Down
32 changes: 32 additions & 0 deletions llvm/lib/Support/SpecialCaseList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ void SpecialCaseList::GlobMatcher::preprocess(bool BySize) {
StringRef Prefix = G.Pattern.prefix();
StringRef Suffix = G.Pattern.suffix();

if (Suffix.empty() && Prefix.empty()) {
// If both prefix and suffix are empty put into special tree to search by
// substring in a middle.
StringRef Substr = G.Pattern.longest_substr();
if (!Substr.empty()) {
// But only if substring is not empty. Searching this tree is more
// expensive.
auto &V = SubstrToGlob.emplace(Substr).first->second;
V.emplace_back(&G);
continue;
}
}

auto &SToGlob = PrefixSuffixToGlob.emplace(Prefix).first->second;
auto &V = SToGlob.emplace(reverse(Suffix)).first->second;
V.emplace_back(&G);
Expand All @@ -119,6 +132,25 @@ void SpecialCaseList::GlobMatcher::match(
}
}
}

if (!SubstrToGlob.empty()) {
// As we don't know when substring exactly starts, we will try all
// possibilities. In most cases search will fail on first characters.
for (StringRef Q = Query; !Q.empty(); Q = Q.drop_front()) {
for (const auto &[_, V] : SubstrToGlob.find_prefixes(Q)) {
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;
}
}
}
}
}
}

SpecialCaseList::Matcher::Matcher(bool UseGlobs, bool RemoveDotSlash)
Expand Down
Loading