Skip to content

Commit 64038ef

Browse files
committed
[ELF] ScriptParser: change std::vector to SmallVector
1 parent e9262ed commit 64038ef

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

Diff for: lld/ELF/Config.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ struct SymbolVersion {
8787
struct VersionDefinition {
8888
llvm::StringRef name;
8989
uint16_t id;
90-
std::vector<SymbolVersion> nonLocalPatterns;
91-
std::vector<SymbolVersion> localPatterns;
90+
SmallVector<SymbolVersion, 0> nonLocalPatterns;
91+
SmallVector<SymbolVersion, 0> localPatterns;
9292
};
9393

9494
// This struct contains the global configuration for the linker.

Diff for: lld/ELF/ScriptParser.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ class ScriptParser final : ScriptLexer {
9393
void readSectionAddressType(OutputSection *cmd);
9494
OutputSection *readOverlaySectionDescription();
9595
OutputSection *readOutputSectionDescription(StringRef outSec);
96-
std::vector<SectionCommand *> readOverlay();
96+
SmallVector<SectionCommand *, 0> readOverlay();
9797
SmallVector<StringRef, 0> readOutputSectionPhdrs();
9898
std::pair<uint64_t, uint64_t> readInputSectionFlags();
9999
InputSectionDescription *readInputSectionDescription(StringRef tok);
100100
StringMatcher readFilePatterns();
101-
std::vector<SectionPattern> readInputSectionsList();
101+
SmallVector<SectionPattern, 0> readInputSectionsList();
102102
InputSectionDescription *readInputSectionRules(StringRef filePattern,
103103
uint64_t withFlags,
104104
uint64_t withoutFlags);
@@ -125,11 +125,11 @@ class ScriptParser final : ScriptLexer {
125125
Expr readParenExpr();
126126

127127
// For parsing version script.
128-
std::vector<SymbolVersion> readVersionExtern();
128+
SmallVector<SymbolVersion, 0> readVersionExtern();
129129
void readAnonymousDeclaration();
130130
void readVersionDeclaration(StringRef verStr);
131131

132-
std::pair<std::vector<SymbolVersion>, std::vector<SymbolVersion>>
132+
std::pair<SmallVector<SymbolVersion, 0>, SmallVector<SymbolVersion, 0>>
133133
readSymbols();
134134

135135
// True if a script being read is in the --sysroot directory.
@@ -181,8 +181,8 @@ static ExprValue bitOr(ExprValue a, ExprValue b) {
181181

182182
void ScriptParser::readDynamicList() {
183183
expect("{");
184-
std::vector<SymbolVersion> locals;
185-
std::vector<SymbolVersion> globals;
184+
SmallVector<SymbolVersion, 0> locals;
185+
SmallVector<SymbolVersion, 0> globals;
186186
std::tie(locals, globals) = readSymbols();
187187
expect(";");
188188

@@ -519,7 +519,7 @@ void ScriptParser::readSearchDir() {
519519
// sections that use the same virtual memory range and normally would trigger
520520
// linker's sections sanity check failures.
521521
// https://sourceware.org/binutils/docs/ld/Overlay-Description.html#Overlay-Description
522-
std::vector<SectionCommand *> ScriptParser::readOverlay() {
522+
SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
523523
// VA and LMA expressions are optional, though for simplicity of
524524
// implementation we assume they are not. That is what OVERLAY was designed
525525
// for first of all: to allow sections with overlapping VAs at different LMAs.
@@ -529,7 +529,7 @@ std::vector<SectionCommand *> ScriptParser::readOverlay() {
529529
Expr lmaExpr = readParenExpr();
530530
expect("{");
531531

532-
std::vector<SectionCommand *> v;
532+
SmallVector<SectionCommand *, 0> v;
533533
OutputSection *prev = nullptr;
534534
while (!errorCount() && !consume("}")) {
535535
// VA is the same for all sections. The LMAs are consecutive in memory
@@ -566,7 +566,7 @@ void ScriptParser::readOverwriteSections() {
566566

567567
void ScriptParser::readSections() {
568568
expect("{");
569-
std::vector<SectionCommand *> v;
569+
SmallVector<SectionCommand *, 0> v;
570570
while (!errorCount() && !consume("}")) {
571571
StringRef tok = next();
572572
if (tok == "OVERLAY") {
@@ -672,8 +672,8 @@ SortSectionPolicy ScriptParser::readSortKind() {
672672
// is parsed as ".foo", ".bar" with "a.o", and ".baz" with "b.o".
673673
// The semantics of that is section .foo in any file, section .bar in
674674
// any file but a.o, and section .baz in any file but b.o.
675-
std::vector<SectionPattern> ScriptParser::readInputSectionsList() {
676-
std::vector<SectionPattern> ret;
675+
SmallVector<SectionPattern, 0> ScriptParser::readInputSectionsList() {
676+
SmallVector<SectionPattern, 0> ret;
677677
while (!errorCount() && peek() != ")") {
678678
StringMatcher excludeFilePat;
679679
if (consume("EXCLUDE_FILE")) {
@@ -718,7 +718,7 @@ ScriptParser::readInputSectionRules(StringRef filePattern, uint64_t withFlags,
718718
while (!errorCount() && !consume(")")) {
719719
SortSectionPolicy outer = readSortKind();
720720
SortSectionPolicy inner = SortSectionPolicy::Default;
721-
std::vector<SectionPattern> v;
721+
SmallVector<SectionPattern, 0> v;
722722
if (outer != SortSectionPolicy::Default) {
723723
expect("(");
724724
inner = readSortKind();
@@ -1494,8 +1494,8 @@ unsigned ScriptParser::readPhdrType() {
14941494

14951495
// Reads an anonymous version declaration.
14961496
void ScriptParser::readAnonymousDeclaration() {
1497-
std::vector<SymbolVersion> locals;
1498-
std::vector<SymbolVersion> globals;
1497+
SmallVector<SymbolVersion, 0> locals;
1498+
SmallVector<SymbolVersion, 0> globals;
14991499
std::tie(locals, globals) = readSymbols();
15001500
for (const SymbolVersion &pat : locals)
15011501
config->versionDefinitions[VER_NDX_LOCAL].localPatterns.push_back(pat);
@@ -1509,8 +1509,8 @@ void ScriptParser::readAnonymousDeclaration() {
15091509
// e.g. "VerStr { global: foo; bar; local: *; };".
15101510
void ScriptParser::readVersionDeclaration(StringRef verStr) {
15111511
// Read a symbol list.
1512-
std::vector<SymbolVersion> locals;
1513-
std::vector<SymbolVersion> globals;
1512+
SmallVector<SymbolVersion, 0> locals;
1513+
SmallVector<SymbolVersion, 0> globals;
15141514
std::tie(locals, globals) = readSymbols();
15151515

15161516
// Create a new version definition and add that to the global symbols.
@@ -1535,11 +1535,11 @@ bool elf::hasWildcard(StringRef s) {
15351535
}
15361536

15371537
// Reads a list of symbols, e.g. "{ global: foo; bar; local: *; };".
1538-
std::pair<std::vector<SymbolVersion>, std::vector<SymbolVersion>>
1538+
std::pair<SmallVector<SymbolVersion, 0>, SmallVector<SymbolVersion, 0>>
15391539
ScriptParser::readSymbols() {
1540-
std::vector<SymbolVersion> locals;
1541-
std::vector<SymbolVersion> globals;
1542-
std::vector<SymbolVersion> *v = &globals;
1540+
SmallVector<SymbolVersion, 0> locals;
1541+
SmallVector<SymbolVersion, 0> globals;
1542+
SmallVector<SymbolVersion, 0> *v = &globals;
15431543

15441544
while (!errorCount()) {
15451545
if (consume("}"))
@@ -1554,7 +1554,7 @@ ScriptParser::readSymbols() {
15541554
}
15551555

15561556
if (consume("extern")) {
1557-
std::vector<SymbolVersion> ext = readVersionExtern();
1557+
SmallVector<SymbolVersion, 0> ext = readVersionExtern();
15581558
v->insert(v->end(), ext.begin(), ext.end());
15591559
} else {
15601560
StringRef tok = next();
@@ -1570,14 +1570,14 @@ ScriptParser::readSymbols() {
15701570
//
15711571
// The last semicolon is optional. E.g. this is OK:
15721572
// "extern "C++" { ns::*; "f(int, double)" };"
1573-
std::vector<SymbolVersion> ScriptParser::readVersionExtern() {
1573+
SmallVector<SymbolVersion, 0> ScriptParser::readVersionExtern() {
15741574
StringRef tok = next();
15751575
bool isCXX = tok == "\"C++\"";
15761576
if (!isCXX && tok != "\"C\"")
15771577
setError("Unknown language");
15781578
expect("{");
15791579

1580-
std::vector<SymbolVersion> ret;
1580+
SmallVector<SymbolVersion, 0> ret;
15811581
while (!errorCount() && peek() != "}") {
15821582
StringRef tok = next();
15831583
ret.push_back(

0 commit comments

Comments
 (0)