@@ -51,41 +51,36 @@ Error SpecialCaseList::RegexMatcher::insert(StringRef Pattern,
5151 if (!CheckRE.isValid (REError))
5252 return createStringError (errc::invalid_argument, REError);
5353
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));
5755 return Error::success ();
5856}
5957
6058void SpecialCaseList::RegexMatcher::match (
6159 StringRef Query,
6260 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 );
6664}
6765
6866Error SpecialCaseList::GlobMatcher::insert (StringRef Pattern,
6967 unsigned LineNumber) {
7068 if (Pattern.empty ())
7169 return createStringError (errc::invalid_argument, " Supplied glob was blank" );
7270
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 ())
7873 return Err;
79- Globs.emplace_back (std::move (G ));
74+ Globs.emplace_back (Pattern, LineNumber, std::move (Res. get () ));
8075 return Error::success ();
8176}
8277
8378void SpecialCaseList::GlobMatcher::match (
8479 StringRef Query,
8580 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 );
8984}
9085
9186SpecialCaseList::Matcher::Matcher (bool UseGlobs, bool RemoveDotSlash)
@@ -167,6 +162,7 @@ SpecialCaseList::addSection(StringRef SectionStr, unsigned FileNo,
167162 Sections.emplace_back (SectionStr, FileNo, UseGlobs);
168163 auto &Section = Sections.back ();
169164
165+ SectionStr = SectionStr.copy (StrAlloc);
170166 if (auto Err = Section.SectionMatcher .insert (SectionStr, LineNo)) {
171167 return createStringError (errc::invalid_argument,
172168 " malformed section at line " + Twine (LineNo) +
@@ -241,6 +237,7 @@ bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB,
241237 auto [It, _] = CurrentSection->Entries [Prefix].try_emplace (
242238 Category, UseGlobs,
243239 RemoveDotSlash && llvm::is_contained (PathPrefixes, Prefix));
240+ Pattern = Pattern.copy (StrAlloc);
244241 if (auto Err = It->second .insert (Pattern, LineNo)) {
245242 Error =
246243 (Twine (" malformed " ) + (UseGlobs ? " glob" : " regex" ) + " in line " +
0 commit comments