Skip to content

Commit e88516c

Browse files
vitalybukagithub-actions[bot]
authored andcommitted
Automerge: [NFC][SpecialCaseList] Add Name into Regex version (#162408)
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.
2 parents 7cf94e7 + 7212d27 commit e88516c

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

llvm/include/llvm/Support/SpecialCaseList.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class SpecialCaseList {
134134
}
135135

136136
struct Glob {
137+
Glob(StringRef Name, unsigned LineNo) : Name(Name), LineNo(LineNo) {}
137138
std::string Name;
138139
unsigned LineNo;
139140
GlobPattern Pattern;
@@ -143,8 +144,18 @@ class SpecialCaseList {
143144
Glob() = default;
144145
};
145146

147+
struct Reg {
148+
Reg(StringRef Name, unsigned LineNo, Regex &&Rg)
149+
: Name(Name), LineNo(LineNo), Rg(std::move(Rg)) {}
150+
std::string Name;
151+
unsigned LineNo;
152+
Regex Rg;
153+
Reg(Reg &&) = delete;
154+
Reg() = default;
155+
};
156+
146157
std::vector<std::unique_ptr<Matcher::Glob>> Globs;
147-
std::vector<std::pair<std::unique_ptr<Regex>, unsigned>> RegExes;
158+
std::vector<std::unique_ptr<Reg>> RegExes;
148159
};
149160

150161
using SectionEntries = StringMap<StringMap<Matcher>>;

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
5252
if (!CheckRE.isValid(REError))
5353
return createStringError(errc::invalid_argument, REError);
5454

55-
RegExes.emplace_back(std::make_pair(
56-
std::make_unique<Regex>(std::move(CheckRE)), LineNumber));
55+
auto Rg =
56+
std::make_unique<Matcher::Reg>(Pattern, LineNumber, std::move(CheckRE));
57+
RegExes.emplace_back(std::move(Rg));
5758

5859
return Error::success();
5960
}
6061

61-
auto Glob = std::make_unique<Matcher::Glob>();
62-
Glob->Name = Pattern.str();
63-
Glob->LineNo = LineNumber;
62+
auto Glob = std::make_unique<Matcher::Glob>(Pattern, LineNumber);
6463
// We must be sure to use the string in `Glob` rather than the provided
6564
// reference which could be destroyed before match() is called
6665
if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024)
@@ -76,9 +75,9 @@ void SpecialCaseList::Matcher::match(
7675
for (const auto &Glob : reverse(Globs))
7776
if (Glob->Pattern.match(Query))
7877
Cb(Glob->Name, Glob->LineNo);
79-
for (const auto &[Regex, LineNumber] : reverse(RegExes))
80-
if (Regex->match(Query))
81-
Cb(/*FIXME: there is no users of this param yet */ "", LineNumber);
78+
for (const auto &Regex : reverse(RegExes))
79+
if (Regex->Rg.match(Query))
80+
Cb(Regex->Name, Regex->LineNo);
8281
}
8382

8483
// TODO: Refactor this to return Expected<...>

0 commit comments

Comments
 (0)