Add [<chars>] to the glob matcher to eliminate use of llvm::Regex.
Previously, it didn't support the character class, so we couldn't
eliminate the use fo llvm::Regex. Now that it is supported, we
can remove compileGlobPattern, which converts a glob pattern to
a regex.
This patch contains optimization for exact/prefix/suffix matches.
Differential Revision: https://reviews.llvm.org/D26284
llvm-svn: 285949
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 1169f83..6b8e39d 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -111,11 +111,11 @@
bool LinkerScript<ELFT>::shouldKeep(InputSectionBase<ELFT> *S) {
for (InputSectionDescription *ID : Opt.KeptSections) {
StringRef Filename = S->getFile()->getName();
- if (!ID->FileRe.match(sys::path::filename(Filename)))
+ if (!ID->FilePat.match(sys::path::filename(Filename)))
continue;
for (SectionPattern &P : ID->SectionPatterns)
- if (P.SectionRe.match(S->Name))
+ if (P.SectionPat.match(S->Name))
return true;
}
return false;
@@ -178,13 +178,13 @@
size_t SizeBefore = I->Sections.size();
for (ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles()) {
StringRef Filename = sys::path::filename(F->getName());
- if (!I->FileRe.match(Filename) || Pat.ExcludedFileRe.match(Filename))
+ if (!I->FilePat.match(Filename) || Pat.ExcludedFilePat.match(Filename))
continue;
for (InputSectionBase<ELFT> *S : F->getSections())
- if (!isDiscarded(S) && !S->OutSec && Pat.SectionRe.match(S->Name))
+ if (!isDiscarded(S) && !S->OutSec && Pat.SectionPat.match(S->Name))
I->Sections.push_back(S);
- if (Pat.SectionRe.match("COMMON"))
+ if (Pat.SectionPat.match("COMMON"))
I->Sections.push_back(InputSection<ELFT>::CommonInputSection);
}
@@ -1211,7 +1211,7 @@
std::vector<StringRef> V;
while (!Error && !consume(")"))
V.push_back(next());
- return StringMatcher(std::move(V));
+ return StringMatcher(V);
}
SortSectionPolicy ScriptParser::readSortKind() {
@@ -1236,10 +1236,10 @@
std::vector<SectionPattern> ScriptParser::readInputSectionsList() {
std::vector<SectionPattern> Ret;
while (!Error && peek() != ")") {
- StringMatcher ExcludeFileRe;
+ StringMatcher ExcludeFilePat;
if (consume("EXCLUDE_FILE")) {
expect("(");
- ExcludeFileRe = readFilePatterns();
+ ExcludeFilePat = readFilePatterns();
}
std::vector<StringRef> V;
@@ -1247,7 +1247,7 @@
V.push_back(next());
if (!V.empty())
- Ret.push_back({std::move(ExcludeFileRe), StringMatcher(std::move(V))});
+ Ret.push_back({std::move(ExcludeFilePat), StringMatcher(V)});
else
setError("section pattern is expected");
}