From: Fangrui Song Date: Wed, 26 Jan 2022 07:33:40 +0000 (-0800) Subject: [ELF] Optimize .relr.dyn to not grow vector. NFC X-Git-Tag: upstream/15.0.7~19126 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=571d6a7120c2b637db2bb46fe3029f9d8576ab86;p=platform%2Fupstream%2Fllvm.git [ELF] Optimize .relr.dyn to not grow vector. NFC --- 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 bool RelrSection::updateAllocSize() { const size_t nBits = wordsize * 8 - 1; // Get offsets for all relative relocations and sort them. - std::vector offsets; - for (const RelativeReloc &rel : relocs) - offsets.push_back(rel.getOffset()); - llvm::sort(offsets); + std::unique_ptr 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;