[lld] bc1369f - [ELF] Optimize MergeInputSection::splitNonStrings with resize_for_overwrite. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 30 00:10:58 PST 2022


Author: Fangrui Song
Date: 2022-01-30T00:10:52-08:00
New Revision: bc1369fae35b7a6fc2cff5282bf24fe3b9a944ee

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

LOG: [ELF] Optimize MergeInputSection::splitNonStrings with resize_for_overwrite. NFC

Added: 
    

Modified: 
    lld/ELF/InputSection.cpp
    lld/ELF/InputSection.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 943cf18e6cf0..570d5f561c15 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -1402,7 +1402,7 @@ void MergeInputSection::splitNonStrings(ArrayRef<uint8_t> data,
   assert((size % entSize) == 0);
   const bool live = !(flags & SHF_ALLOC) || !config->gcSections;
 
-  pieces.assign(size / entSize, SectionPiece(0, 0, false));
+  pieces.resize_for_overwrite(size / entSize);
   for (size_t i = 0, j = 0; i != size; i += entSize, j++)
     pieces[j] = {i, (uint32_t)xxHash64(data.slice(i, entSize)), live};
 }

diff  --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 0b8012514139..adfc45ece9bc 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -242,6 +242,7 @@ class InputSectionBase : public SectionBase {
 // have to be as compact as possible, which is why we don't store the size (can
 // be found by looking at the next one).
 struct SectionPiece {
+  SectionPiece() = default;
   SectionPiece(size_t off, uint32_t hash, bool live)
       : inputOff(off), live(live), hash(hash >> 1) {}
 


        


More information about the llvm-commits mailing list