Skip to content

Commit 95a36a5

Browse files
ColibrowMaskRay
authored andcommitted
change content hash as llvm#121729
1 parent 5569078 commit 95a36a5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lld/ELF/BPSectionOrderer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ void BPSectionELF::getSectionHashes(
1717
const llvm::DenseMap<const void *, uint64_t> &sectionToIdx) const {
1818
constexpr unsigned windowSize = 4;
1919

20-
size_t size = isec->content().size();
21-
for (size_t i = 0; i != size; ++i) {
22-
auto window = isec->content().drop_front(i).take_front(windowSize);
23-
hashes.push_back(xxHash64(window));
24-
}
20+
// Calculate content hashes: k-mers and the last k-1 bytes.
21+
ArrayRef<uint8_t> data = isec->content();
22+
if (data.size() >= windowSize)
23+
for (size_t i = 0; i <= data.size() - windowSize; ++i)
24+
hashes.push_back(llvm::support::endian::read32le(data.data() + i));
25+
for (uint8_t byte : data.take_back(windowSize - 1))
26+
hashes.push_back(byte);
2527

2628
llvm::sort(hashes);
2729
hashes.erase(std::unique(hashes.begin(), hashes.end()), hashes.end());

0 commit comments

Comments
 (0)