[lld] 2c8ebab - [ELF] sortSymTabSymbols: change vector to SmallVector

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 25 23:16:34 PST 2021


Author: Fangrui Song
Date: 2021-12-25T23:16:27-08:00
New Revision: 2c8ebab32eadbc749e669a6529d6a40929ae5d14

URL: https://github.com/llvm/llvm-project/commit/2c8ebab32eadbc749e669a6529d6a40929ae5d14
DIFF: https://github.com/llvm/llvm-project/commit/2c8ebab32eadbc749e669a6529d6a40929ae5d14.diff

LOG: [ELF] sortSymTabSymbols: change vector to SmallVector

This function may take ~1% time. SmallVector<SymbolTableEntry, 0> is smaller (16 bytes
instead of 24) and more efficient.

Added: 
    

Modified: 
    lld/ELF/SyntheticSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index e480118f5ae9c..b8775097f1fc9 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2127,12 +2127,12 @@ void SymbolTableBaseSection::sortSymTabSymbols() {
   // symbols, they are already naturally placed first in each group. That
   // happens because STT_FILE is always the first symbol in the object and hence
   // precede all other local symbols we add for a file.
-  MapVector<InputFile *, std::vector<SymbolTableEntry>> arr;
+  MapVector<InputFile *, SmallVector<SymbolTableEntry, 0>> arr;
   for (const SymbolTableEntry &s : llvm::make_range(symbols.begin(), e))
     arr[s.sym->file].push_back(s);
 
   auto i = symbols.begin();
-  for (std::pair<InputFile *, std::vector<SymbolTableEntry>> &p : arr)
+  for (auto &p : arr)
     for (SymbolTableEntry &entry : p.second)
       *i++ = entry;
 }


        


More information about the llvm-commits mailing list