@@ -49,9 +49,7 @@ impl HashSecret {
4949 let k1 = u64:: from_le_bytes ( right. try_into ( ) . unwrap ( ) ) ;
5050 Self { k0, k1 }
5151 }
52- }
5352
54- impl HashSecret {
5553 pub fn hash_value < T : Hash + ?Sized > ( & self , data : & T ) -> PyHash {
5654 fix_sentinel ( mod_int ( self . hash_one ( data) as _ ) )
5755 }
@@ -94,7 +92,7 @@ pub const fn hash_pointer(value: usize) -> PyHash {
9492
9593#[ inline]
9694#[ must_use]
97- pub fn hash_float ( value : f64 ) -> Option < PyHash > {
95+ pub const fn hash_float ( value : f64 ) -> Option < PyHash > {
9896 // cpython _Py_HashDouble
9997 if !value. is_finite ( ) {
10098 return if value. is_infinite ( ) {
@@ -111,6 +109,8 @@ pub fn hash_float(value: f64) -> Option<PyHash> {
111109 let mut m = frexp. 0 ;
112110 let mut e = frexp. 1 ;
113111 let mut x: PyUHash = 0 ;
112+
113+ #[ expect( clippy:: while_float, reason = "keep this loop like CPython does it" ) ]
114114 while m != 0.0 {
115115 x = ( ( x << 28 ) & MODULUS ) | ( x >> ( BITS - 28 ) ) ;
116116 m *= 268_435_456.0 ; // 2**28
@@ -137,13 +137,14 @@ pub fn hash_float(value: f64) -> Option<PyHash> {
137137
138138#[ must_use]
139139pub fn hash_bigint ( value : & BigInt ) -> PyHash {
140- let ret = match value. to_i64 ( ) {
141- Some ( i ) => mod_int ( i ) ,
142- None => ( value % MODULUS ) . to_i64 ( ) . unwrap_or_else ( || unsafe {
143- // SAFETY: MODULUS < i64::MAX, so value % MODULUS is guaranteed to be in the range of i64
144- core :: hint :: unreachable_unchecked ( )
145- } ) ,
140+ let ret = if let Some ( v ) = value. to_i64 ( ) {
141+ mod_int ( v )
142+ } else {
143+ // SAFETY:
144+ // MODULUS < i64::MAX, so value % MODULUS is guaranteed to be in the range of i64
145+ unsafe { ( value % MODULUS ) . to_i64 ( ) . unwrap_unchecked ( ) }
146146 } ;
147+
147148 fix_sentinel ( ret)
148149}
149150
0 commit comments