[llvm] [NFC][SpecialCaseList] Add Name into Regex version (PR #162408)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 7 17:51:18 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Vitaly Buka (vitalybuka)
<details>
<summary>Changes</summary>
To pass something into Cb in `match()`.
No need to bother with test coverage, as it's
legacy transitional code, maybe we can remove it
soon.
---
Full diff: https://github.com/llvm/llvm-project/pull/162408.diff
2 Files Affected:
- (modified) llvm/include/llvm/Support/SpecialCaseList.h (+12-1)
- (modified) llvm/lib/Support/SpecialCaseList.cpp (+7-8)
``````````diff
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<std::unique_ptr<Matcher::Glob>> Globs;
- std::vector<std::pair<std::unique_ptr<Regex>, unsigned>> RegExes;
+ std::vector<std::unique_ptr<Reg>> RegExes;
};
using SectionEntries = StringMap<StringMap<Matcher>>;
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<Regex>(std::move(CheckRE)), LineNumber));
+ auto Rg =
+ std::make_unique<Matcher::Reg>(Pattern, LineNumber, std::move(CheckRE));
+ RegExes.emplace_back(std::move(Rg));
return Error::success();
}
- auto Glob = std::make_unique<Matcher::Glob>();
- Glob->Name = Pattern.str();
- Glob->LineNo = LineNumber;
+ auto Glob = std::make_unique<Matcher::Glob>(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<...>
``````````
</details>
https://github.com/llvm/llvm-project/pull/162408
More information about the llvm-commits
mailing list