diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h index a235975b152c3..860f73c798e41 100644 --- a/llvm/include/llvm/Support/SpecialCaseList.h +++ b/llvm/include/llvm/Support/SpecialCaseList.h @@ -167,8 +167,9 @@ class SpecialCaseList { std::vector Globs; RadixTree, - SmallVector> - PrefixToGlob; + RadixTree, + SmallVector>> + PrefixSuffixToGlob; }; /// Represents a set of patterns and their line numbers diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp index c27f627446203..3a9718569a06f 100644 --- a/llvm/lib/Support/SpecialCaseList.cpp +++ b/llvm/lib/Support/SpecialCaseList.cpp @@ -92,8 +92,10 @@ 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); } } @@ -101,16 +103,18 @@ void SpecialCaseList::GlobMatcher::preprocess(bool BySize) { void SpecialCaseList::GlobMatcher::match( StringRef Query, llvm::function_ref 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; + } } } }