Skip to content

Commit 4e4f95d

Browse files
Nicoshevfacebook-github-bot
authored andcommitted
Use folly::constexprLoadUnaligned within rapidhash
Summary: As promised during inital review, refactor rapidhash use the new folly::constexprLoadUnaligned instead of defining new constexpr loading functions Reviewed By: yfeldblum Differential Revision: D76559267 fbshipit-source-id: 08c26ec34893233ffcdac13e4d6b78f7641a2b5b
1 parent 7d24819 commit 4e4f95d

File tree

1 file changed

+3
-32
lines changed
  • third-party/folly/src/folly/external/rapidhash

1 file changed

+3
-32
lines changed

third-party/folly/src/folly/external/rapidhash/rapidhash.h

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -143,43 +143,14 @@ rapidhash_mix(uint64_t A, uint64_t B) noexcept {
143143
/*
144144
* Read functions.
145145
*/
146-
FOLLY_EXTERNAL_RAPIDHASH_INLINE_CONSTEXPR std::uint64_t rapidhash_read32_cx(const char* s) {
147-
static_assert(kIsLittleEndian);
148-
std::uint64_t ret = 0;
149-
ret |= std::uint64_t(static_cast<uint8_t>(s[0])) << (0 * 8);
150-
ret |= std::uint64_t(static_cast<uint8_t>(s[1])) << (1 * 8);
151-
ret |= std::uint64_t(static_cast<uint8_t>(s[2])) << (2 * 8);
152-
ret |= std::uint64_t(static_cast<uint8_t>(s[3])) << (3 * 8);
153-
return ret;
154-
}
155-
156-
FOLLY_EXTERNAL_RAPIDHASH_INLINE_CONSTEXPR uint64_t
146+
FOLLY_EXTERNAL_RAPIDHASH_INLINE_CONSTEXPR uint32_t
157147
rapidhash_read32(const char* p) noexcept {
158-
if (folly::is_constant_evaluated_or(false) && kIsLittleEndian) {
159-
return rapidhash_read32_cx(p);
160-
} else {
161-
return folly::Endian::little(loadUnaligned<std::uint32_t>(p));
162-
}
163-
}
164-
165-
FOLLY_EXTERNAL_RAPIDHASH_INLINE_CONSTEXPR std::uint64_t rapidhash_read64_cx(
166-
const char* s, std::size_t l) {
167-
static_assert(kIsLittleEndian);
168-
169-
std::uint64_t ret = 0;
170-
for (std::size_t i = 0; i < l; ++i) {
171-
ret |= std::uint64_t(static_cast<uint8_t>(s[i])) << (i * 8);
172-
}
173-
return ret;
148+
return folly::constexprLoadUnaligned<uint32_t, char>(p);
174149
}
175150

176151
FOLLY_EXTERNAL_RAPIDHASH_INLINE_CONSTEXPR uint64_t
177152
rapidhash_read64(const char* p) noexcept {
178-
if (folly::is_constant_evaluated_or(false) && kIsLittleEndian) {
179-
return rapidhash_read64_cx(p, 8);
180-
} else {
181-
return folly::Endian::little(loadUnaligned<std::uint64_t>(p));
182-
}
153+
return folly::constexprLoadUnaligned<uint64_t, char>(p);
183154
}
184155

185156
/*

0 commit comments

Comments
 (0)