File tree Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Original file line number Diff line number Diff line change @@ -257,24 +257,18 @@ const fn multiply_mix(x: u64, y: u64) -> u64 {
257
257
258
258
// Const compatible helper function to read a u64 from a byte array at a given
259
259
// offset
260
+ #[ inline( always) ]
260
261
const fn read_u64_le ( bytes : & [ u8 ] , offset : usize ) -> u64 {
261
- ( bytes[ offset] as u64 )
262
- | ( ( bytes[ offset + 1 ] as u64 ) << 8 )
263
- | ( ( bytes[ offset + 2 ] as u64 ) << 16 )
264
- | ( ( bytes[ offset + 3 ] as u64 ) << 24 )
265
- | ( ( bytes[ offset + 4 ] as u64 ) << 32 )
266
- | ( ( bytes[ offset + 5 ] as u64 ) << 40 )
267
- | ( ( bytes[ offset + 6 ] as u64 ) << 48 )
268
- | ( ( bytes[ offset + 7 ] as u64 ) << 56 )
262
+ let array = unsafe { bytes. as_ptr ( ) . add ( offset) } as * const [ u8 ; 8 ] ;
263
+ u64:: from_le_bytes ( unsafe { * array } )
269
264
}
270
265
271
266
// Const compatible helper function to read a u32 from a byte array at a given
272
267
// offset
268
+ #[ inline( always) ]
273
269
const fn read_u32_le ( bytes : & [ u8 ] , offset : usize ) -> u32 {
274
- ( bytes[ offset] as u32 )
275
- | ( ( bytes[ offset + 1 ] as u32 ) << 8 )
276
- | ( ( bytes[ offset + 2 ] as u32 ) << 16 )
277
- | ( ( bytes[ offset + 3 ] as u32 ) << 24 )
270
+ let array = unsafe { bytes. as_ptr ( ) . add ( offset) } as * const [ u8 ; 4 ] ;
271
+ u32:: from_le_bytes ( unsafe { * array } )
278
272
}
279
273
280
274
/// Copied from `hash_bytes` of `rustc-hash`.
You can’t perform that action at this time.
0 commit comments