diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h index bb382f64b084f..64cad804ad911 100644 --- a/llvm/include/llvm/Support/SpecialCaseList.h +++ b/llvm/include/llvm/Support/SpecialCaseList.h @@ -134,6 +134,7 @@ class SpecialCaseList { } struct Glob { + Glob(StringRef Name, unsigned LineNo) : Name(Name), LineNo(LineNo) {} std::string Name; unsigned LineNo; GlobPattern Pattern; @@ -143,8 +144,18 @@ class SpecialCaseList { Glob() = default; }; + struct Reg { + Reg(StringRef Name, unsigned LineNo, Regex &&Rg) + : Name(Name), LineNo(LineNo), Rg(std::move(Rg)) {} + std::string Name; + unsigned LineNo; + Regex Rg; + Reg(Reg &&) = delete; + Reg() = default; + }; + std::vector> Globs; - std::vector, unsigned>> RegExes; + std::vector> RegExes; }; using SectionEntries = StringMap>; diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp index 9a1b47faab3ed..6ad8d7d4e7ffa 100644 --- a/llvm/lib/Support/SpecialCaseList.cpp +++ b/llvm/lib/Support/SpecialCaseList.cpp @@ -52,15 +52,14 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber, if (!CheckRE.isValid(REError)) return createStringError(errc::invalid_argument, REError); - RegExes.emplace_back(std::make_pair( - std::make_unique(std::move(CheckRE)), LineNumber)); + auto Rg = + std::make_unique(Pattern, LineNumber, std::move(CheckRE)); + RegExes.emplace_back(std::move(Rg)); return Error::success(); } - auto Glob = std::make_unique(); - Glob->Name = Pattern.str(); - Glob->LineNo = LineNumber; + auto Glob = std::make_unique(Pattern, LineNumber); // We must be sure to use the string in `Glob` rather than the provided // reference which could be destroyed before match() is called if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024) @@ -76,9 +75,9 @@ void SpecialCaseList::Matcher::match( for (const auto &Glob : reverse(Globs)) if (Glob->Pattern.match(Query)) Cb(Glob->Name, Glob->LineNo); - for (const auto &[Regex, LineNumber] : reverse(RegExes)) - if (Regex->match(Query)) - Cb(/*FIXME: there is no users of this param yet */ "", LineNumber); + for (const auto &Regex : reverse(RegExes)) + if (Regex->Rg.match(Query)) + Cb(Regex->Name, Regex->LineNo); } // TODO: Refactor this to return Expected<...>