aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF/SyntheticSections.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2022-01-25 23:33:40 -0800
committerFangrui Song <i@maskray.me>2022-01-25 23:33:40 -0800
commit571d6a7120c2b637db2bb46fe3029f9d8576ab86 (patch)
tree662237d6415df5ebe60d95ea5a17e5af18a53b19 /lld/ELF/SyntheticSections.cpp
parentf563bd74cb9a4f0d2d3eb49d35536b648361ec53 (diff)
downloadllvm-571d6a7120c2b637db2bb46fe3029f9d8576ab86.zip
llvm-571d6a7120c2b637db2bb46fe3029f9d8576ab86.tar.gz
llvm-571d6a7120c2b637db2bb46fe3029f9d8576ab86.tar.bz2
[ELF] Optimize .relr.dyn to not grow vector<uint64_t>. NFC
Diffstat (limited to 'lld/ELF/SyntheticSections.cpp')
-rw-r--r--lld/ELF/SyntheticSections.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 9f0cbf9..f442aca 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2024,14 +2024,14 @@ template <class ELFT> bool RelrSection<ELFT>::updateAllocSize() {
const size_t nBits = wordsize * 8 - 1;
// Get offsets for all relative relocations and sort them.
- std::vector<uint64_t> offsets;
- for (const RelativeReloc &rel : relocs)
- offsets.push_back(rel.getOffset());
- llvm::sort(offsets);
+ std::unique_ptr<uint64_t[]> offsets(new uint64_t[relocs.size()]);
+ for (auto it : llvm::enumerate(relocs))
+ offsets[it.index()] = it.value().getOffset();
+ std::sort(offsets.get(), offsets.get() + relocs.size());
// For each leading relocation, find following ones that can be folded
// as a bitmap and fold them.
- for (size_t i = 0, e = offsets.size(); i < e;) {
+ for (size_t i = 0, e = relocs.size(); i != e;) {
// Add a leading relocation.
relrRelocs.push_back(Elf_Relr(offsets[i]));
uint64_t base = offsets[i] + wordsize;