Skip to content

Commit 568368a

Browse files
[Support] Make readNext default to unaligned (#88808)
Without this patch, you would typically use readNext as: readNext<uint32_t, llvm::endianness::little, unaligned>(Ptr) which is quite mouthful. Since most serialization/deserialization operations are unaligned accesses, this patch makes the alignment template parameter default to unaligned, allowing us to say: readNext<uint32_t, llvm::endianness::little>(Ptr) I'm including a few examples of migration in this patch. I'll do the rest in a separate patch. Note that writeNext already has the same trick for the alignment template parameter.
1 parent 5f68072 commit 568368a

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

llvm/include/llvm/Support/Endian.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ template <typename value_type, std::size_t alignment, typename CharT>
8080
return ret;
8181
}
8282

83-
template <typename value_type, endianness endian, std::size_t alignment,
84-
typename CharT>
83+
template <typename value_type, endianness endian,
84+
std::size_t alignment = unaligned, typename CharT>
8585
[[nodiscard]] inline value_type readNext(const CharT *&memory) {
8686
return readNext<value_type, alignment, CharT>(memory, endian);
8787
}

llvm/include/llvm/Support/OnDiskHashTable.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,12 @@ template <typename Info> class OnDiskChainedHashTable {
368368

369369
// 'Items' starts with a 16-bit unsigned integer representing the
370370
// number of items in this bucket.
371-
unsigned Len =
372-
endian::readNext<uint16_t, llvm::endianness::little, unaligned>(Items);
371+
unsigned Len = endian::readNext<uint16_t, llvm::endianness::little>(Items);
373372

374373
for (unsigned i = 0; i < Len; ++i) {
375374
// Read the hash.
376375
hash_value_type ItemHash =
377-
endian::readNext<hash_value_type, llvm::endianness::little,
378-
unaligned>(Items);
376+
endian::readNext<hash_value_type, llvm::endianness::little>(Items);
379377

380378
// Determine the length of the key and the data.
381379
const std::pair<offset_type, offset_type> &L =
@@ -473,8 +471,7 @@ class OnDiskIterableChainedHashTable : public OnDiskChainedHashTable<Info> {
473471
// 'Items' starts with a 16-bit unsigned integer representing the
474472
// number of items in this bucket.
475473
NumItemsInBucketLeft =
476-
endian::readNext<uint16_t, llvm::endianness::little, unaligned>(
477-
Ptr);
474+
endian::readNext<uint16_t, llvm::endianness::little>(Ptr);
478475
}
479476
Ptr += sizeof(hash_value_type); // Skip the hash.
480477
// Determine the length of the key and the data.

0 commit comments

Comments
 (0)