@@ -51,41 +51,36 @@ Error SpecialCaseList::RegexMatcher::insert(StringRef Pattern,
51
51
if (!CheckRE.isValid (REError))
52
52
return createStringError (errc::invalid_argument, REError);
53
53
54
- auto Rg = std::make_unique<Reg>(Pattern, LineNumber, std::move (CheckRE));
55
- RegExes.emplace_back (std::move (Rg));
56
-
54
+ RegExes.emplace_back (Pattern, LineNumber, std::move (CheckRE));
57
55
return Error::success ();
58
56
}
59
57
60
58
void SpecialCaseList::RegexMatcher::match (
61
59
StringRef Query,
62
60
llvm::function_ref<void (StringRef Rule, unsigned LineNo)> Cb) const {
63
- for (const auto &Regex : reverse (RegExes))
64
- if (Regex-> Rg .match (Query))
65
- Cb (Regex-> Name , Regex-> LineNo );
61
+ for (const auto &R : reverse (RegExes))
62
+ if (R. Rg .match (Query))
63
+ Cb (R. Name , R. LineNo );
66
64
}
67
65
68
66
Error SpecialCaseList::GlobMatcher::insert (StringRef Pattern,
69
67
unsigned LineNumber) {
70
68
if (Pattern.empty ())
71
69
return createStringError (errc::invalid_argument, " Supplied glob was blank" );
72
70
73
- auto G = std::make_unique<Glob>(Pattern, LineNumber);
74
- // We must be sure to use the string in `Glob` rather than the provided
75
- // reference which could be destroyed before match() is called
76
- if (auto Err = GlobPattern::create (G->Name , /* MaxSubPatterns=*/ 1024 )
77
- .moveInto (G->Pattern ))
71
+ auto Res = GlobPattern::create (Pattern, /* MaxSubPatterns=*/ 1024 );
72
+ if (auto Err = Res.takeError ())
78
73
return Err;
79
- Globs.emplace_back (std::move (G ));
74
+ Globs.emplace_back (Pattern, LineNumber, std::move (Res. get () ));
80
75
return Error::success ();
81
76
}
82
77
83
78
void SpecialCaseList::GlobMatcher::match (
84
79
StringRef Query,
85
80
llvm::function_ref<void (StringRef Rule, unsigned LineNo)> Cb) const {
86
- for (const auto &Glob : reverse (Globs))
87
- if (Glob-> Pattern .match (Query))
88
- Cb (Glob-> Name , Glob-> LineNo );
81
+ for (const auto &G : reverse (Globs))
82
+ if (G. Pattern .match (Query))
83
+ Cb (G. Name , G. LineNo );
89
84
}
90
85
91
86
SpecialCaseList::Matcher::Matcher (bool UseGlobs, bool RemoveDotSlash)
@@ -167,6 +162,7 @@ SpecialCaseList::addSection(StringRef SectionStr, unsigned FileNo,
167
162
Sections.emplace_back (SectionStr, FileNo, UseGlobs);
168
163
auto &Section = Sections.back ();
169
164
165
+ SectionStr = SectionStr.copy (StrAlloc);
170
166
if (auto Err = Section.SectionMatcher .insert (SectionStr, LineNo)) {
171
167
return createStringError (errc::invalid_argument,
172
168
" malformed section at line " + Twine (LineNo) +
@@ -241,6 +237,7 @@ bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB,
241
237
auto [It, _] = CurrentSection->Entries [Prefix].try_emplace (
242
238
Category, UseGlobs,
243
239
RemoveDotSlash && llvm::is_contained (PathPrefixes, Prefix));
240
+ Pattern = Pattern.copy (StrAlloc);
244
241
if (auto Err = It->second .insert (Pattern, LineNo)) {
245
242
Error =
246
243
(Twine (" malformed " ) + (UseGlobs ? " glob" : " regex" ) + " in line " +
0 commit comments