Skip to content

Commit ba948c5

Browse files
committed
[ELF] Use SmallVector for some global variables (*Files and *Sections). NFC
My lld executable is 26+KiB smaller.
1 parent 856550c commit ba948c5

7 files changed

+17
-17
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ using namespace lld::elf;
4343
bool InputFile::isInGroup;
4444
uint32_t InputFile::nextGroupId;
4545

46-
std::vector<ArchiveFile *> elf::archiveFiles;
47-
std::vector<BinaryFile *> elf::binaryFiles;
48-
std::vector<BitcodeFile *> elf::bitcodeFiles;
49-
std::vector<BitcodeFile *> elf::lazyBitcodeFiles;
50-
std::vector<ELFFileBase *> elf::objectFiles;
51-
std::vector<SharedFile *> elf::sharedFiles;
46+
SmallVector<ArchiveFile *, 0> elf::archiveFiles;
47+
SmallVector<BinaryFile *, 0> elf::binaryFiles;
48+
SmallVector<BitcodeFile *, 0> elf::bitcodeFiles;
49+
SmallVector<BitcodeFile *, 0> elf::lazyBitcodeFiles;
50+
SmallVector<ELFFileBase *, 0> elf::objectFiles;
51+
SmallVector<SharedFile *, 0> elf::sharedFiles;
5252

5353
std::unique_ptr<TarWriter> elf::tar;
5454

lld/ELF/InputFiles.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,12 @@ inline bool isBitcode(MemoryBufferRef mb) {
396396

397397
std::string replaceThinLTOSuffix(StringRef path);
398398

399-
extern std::vector<ArchiveFile *> archiveFiles;
400-
extern std::vector<BinaryFile *> binaryFiles;
401-
extern std::vector<BitcodeFile *> bitcodeFiles;
402-
extern std::vector<BitcodeFile *> lazyBitcodeFiles;
403-
extern std::vector<ELFFileBase *> objectFiles;
404-
extern std::vector<SharedFile *> sharedFiles;
399+
extern SmallVector<ArchiveFile *, 0> archiveFiles;
400+
extern SmallVector<BinaryFile *, 0> binaryFiles;
401+
extern SmallVector<BitcodeFile *, 0> bitcodeFiles;
402+
extern SmallVector<BitcodeFile *, 0> lazyBitcodeFiles;
403+
extern SmallVector<ELFFileBase *, 0> objectFiles;
404+
extern SmallVector<SharedFile *, 0> sharedFiles;
405405

406406
} // namespace elf
407407
} // namespace lld

lld/ELF/InputSection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ using namespace llvm::sys;
4040
using namespace lld;
4141
using namespace lld::elf;
4242

43-
std::vector<InputSectionBase *> elf::inputSections;
43+
SmallVector<InputSectionBase *, 0> elf::inputSections;
4444
DenseSet<std::pair<const Symbol *, uint64_t>> elf::ppc64noTocRelax;
4545

4646
// Returns a string to construct an error message.

lld/ELF/InputSection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ inline bool isDebugSection(const InputSectionBase &sec) {
394394
}
395395

396396
// The list of all input sections.
397-
extern std::vector<InputSectionBase *> inputSections;
397+
extern SmallVector<InputSectionBase *, 0> inputSections;
398398

399399
// The set of TOC entries (.toc + addend) for which we should not apply
400400
// toc-indirect to toc-relative relaxation. const Symbol * refers to the

lld/ELF/OutputSections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ OutputSection *Out::preinitArray;
4040
OutputSection *Out::initArray;
4141
OutputSection *Out::finiArray;
4242

43-
std::vector<OutputSection *> elf::outputSections;
43+
SmallVector<OutputSection *, 0> elf::outputSections;
4444

4545
uint32_t OutputSection::getPhdrFlags() const {
4646
uint32_t ret = 0;

lld/ELF/OutputSections.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct Out {
138138

139139
uint64_t getHeaderSize();
140140

141-
extern std::vector<OutputSection *> outputSections;
141+
extern llvm::SmallVector<OutputSection *, 0> outputSections;
142142
} // namespace elf
143143
} // namespace lld
144144

lld/ELF/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ static void maybeShuffle(DenseMap<const InputSectionBase *, int> &order) {
12461246
if (config->shuffleSections.empty())
12471247
return;
12481248

1249-
std::vector<InputSectionBase *> matched, sections = inputSections;
1249+
SmallVector<InputSectionBase *, 0> matched, sections = inputSections;
12501250
matched.reserve(sections.size());
12511251
for (const auto &patAndSeed : config->shuffleSections) {
12521252
matched.clear();

0 commit comments

Comments
 (0)