[lld] fcd8817 - [ELF] Simplify maybeCompress with lld::split. NFC

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


Author: Fangrui Song
Date: 2022-01-30T00:44:19-08:00
New Revision: fcd8817da509f0b5dfbc7014f288ab7a5b69f28b

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

LOG: [ELF] Simplify maybeCompress with lld::split. NFC

Added: 
    

Modified: 
    lld/ELF/OutputSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index c73d6e439238..c036d54a0526 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -12,6 +12,7 @@
 #include "SymbolTable.h"
 #include "SyntheticSections.h"
 #include "Target.h"
+#include "lld/Common/Arrays.h"
 #include "lld/Common/Memory.h"
 #include "lld/Common/Strings.h"
 #include "llvm/BinaryFormat/Dwarf.h"
@@ -342,12 +343,8 @@ template <class ELFT> void OutputSection::maybeCompress() {
 
   // Split input into 1-MiB shards.
   constexpr size_t shardSize = 1 << 20;
-  const size_t numShards = (size + shardSize - 1) / shardSize;
-  auto shardsIn = std::make_unique<ArrayRef<uint8_t>[]>(numShards);
-  for (size_t i = 0, start = 0, end; start != size; ++i, start = end) {
-    end = std::min(start + shardSize, (size_t)size);
-    shardsIn[i] = makeArrayRef<uint8_t>(buf.get() + start, end - start);
-  }
+  auto shardsIn = split(makeArrayRef<uint8_t>(buf.get(), size), shardSize);
+  const size_t numShards = shardsIn.size();
 
   // Compress shards and compute Alder-32 checksums. Use Z_SYNC_FLUSH for all
   // shards but the last to flush the output to a byte boundary to be


        


More information about the llvm-commits mailing list