File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff 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) ]
140147fn 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
You can’t perform that action at this time.
0 commit comments