[lld] 571d6a7 - [ELF] Optimize .relr.dyn to not grow vector<uint64_t>. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 25 23:33:46 PST 2022


Author: Fangrui Song
Date: 2022-01-25T23:33:40-08:00
New Revision: 571d6a7120c2b637db2bb46fe3029f9d8576ab86

URL: https://github.com/llvm/llvm-project/commit/571d6a7120c2b637db2bb46fe3029f9d8576ab86
DIFF: https://github.com/llvm/llvm-project/commit/571d6a7120c2b637db2bb46fe3029f9d8576ab86.diff

LOG: [ELF] Optimize .relr.dyn to not grow vector<uint64_t>. NFC

Added: 
    

Modified: 
    lld/ELF/SyntheticSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 9f0cbf9e8488..f442acaafe85 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;


        


More information about the llvm-commits mailing list