Skip to content

Commit f3fa266

Browse files
committed
Make usize::min(mem::size_of::<usize>(), mem::size_of::<u64>()) const
1 parent 3831650 commit f3fa266

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/raw/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,22 @@ fn h1(hash: u64) -> usize {
134134
hash as usize
135135
}
136136

137+
// Constant for h2 function that grabing the top 7 bits of the hash.
138+
const MIN_HASH_LEN: usize = if mem::size_of::<usize>() < mem::size_of::<u64>() {
139+
mem::size_of::<usize>()
140+
} else {
141+
mem::size_of::<u64>()
142+
};
143+
137144
/// Secondary hash function, saved in the low 7 bits of the control byte.
138145
#[inline]
139146
#[allow(clippy::cast_possible_truncation)]
140147
fn h2(hash: u64) -> u8 {
141148
// Grab the top 7 bits of the hash. While the hash is normally a full 64-bit
142149
// value, some hash functions (such as FxHash) produce a usize result
143150
// instead, which means that the top 32 bits are 0 on 32-bit platforms.
144-
let hash_len = usize::min(mem::size_of::<usize>(), mem::size_of::<u64>());
145-
let top7 = hash >> (hash_len * 8 - 7);
151+
// So we use MIN_HASH_LEN constant to handle this.
152+
let top7 = hash >> (MIN_HASH_LEN * 8 - 7);
146153
(top7 & 0x7f) as u8 // truncation
147154
}
148155

0 commit comments

Comments
 (0)