Skip to content

Commit

Permalink
fix cargo +nightly build (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz authored Jul 24, 2024
1 parent 858ebe7 commit 6c3bc62
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/utils/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use indexmap::IndexMap as StdHashMap;
#[cfg(all(not(feature = "enhanced-determinism"), feature = "serde-serialize"))]
use std::collections::HashMap as StdHashMap;

use std::mem::size_of;

/// Serializes only the capacity of a hash-map instead of its actual content.
#[cfg(feature = "serde-serialize")]
pub fn serialize_hashmap_capacity<S: serde::Serializer, K, V, H: std::hash::BuildHasher>(
Expand Down Expand Up @@ -84,20 +86,20 @@ impl std::hash::Hasher for FxHasher32 {
fn write(&mut self, mut bytes: &[u8]) {
let read_u32 = |bytes: &[u8]| u32::from_ne_bytes(bytes[..4].try_into().unwrap());
let mut hash = FxHasher32 { hash: self.hash };
assert!(std::mem::size_of::<u32>() <= 8);
while bytes.len() >= std::mem::size_of::<u32>() {
assert!(size_of::<u32>() <= 8);
while bytes.len() >= size_of::<u32>() {
hash.add_to_hash(read_u32(bytes));
bytes = &bytes[std::mem::size_of::<u32>()..];
bytes = &bytes[size_of::<u32>()..];
}
if (std::mem::size_of::<u32>() > 4) && (bytes.len() >= 4) {
if (size_of::<u32>() > 4) && (bytes.len() >= 4) {
hash.add_to_hash(u32::from_ne_bytes(bytes[..4].try_into().unwrap()));
bytes = &bytes[4..];
}
if (std::mem::size_of::<u32>() > 2) && bytes.len() >= 2 {
if (size_of::<u32>() > 2) && bytes.len() >= 2 {
hash.add_to_hash(u16::from_ne_bytes(bytes[..2].try_into().unwrap()) as u32);
bytes = &bytes[2..];
}
if (std::mem::size_of::<u32>() > 1) && !bytes.is_empty() {
if (size_of::<u32>() > 1) && !bytes.is_empty() {
hash.add_to_hash(bytes[0] as u32);
}
self.hash = hash.hash;
Expand Down

0 comments on commit 6c3bc62

Please sign in to comment.