Skip to content

Commit

Permalink
chore(primitives): remove rustc-hash workaround (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Dec 10, 2024
1 parent 75b87b9 commit 0fdb0b5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ sha3 = { version = "0.10.8", default-features = false }
hashbrown = { version = "0.15", default-features = false }
indexmap = { version = "2.5", default-features = false }
foldhash = { version = "0.1", default-features = false }
rustc-hash = { version = "2.0", default-features = false }
rustc-hash = { version = "2.1", default-features = false }

# misc
allocative = { version = "0.3.2", default-features = false }
Expand Down
37 changes: 2 additions & 35 deletions crates/primitives/src/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,40 +65,7 @@ cfg_if! {

cfg_if! {
if #[cfg(all(feature = "std", feature = "rand"))] {
// use rustc_hash::FxRandomState as FxBuildHasherInner;

// TODO: Polyfill for https://github.com/rust-lang/rustc-hash/pull/52/
#[allow(missing_debug_implementations, missing_copy_implementations)]
#[doc(hidden)]
#[derive(Clone)]
pub struct FxBuildHasherInner(usize);

impl Default for FxBuildHasherInner {
// Copied from `FxRandomState::new`.
fn default() -> Self {
use rand::Rng;
use std::{cell::Cell, thread_local};

thread_local!(static SEED: Cell<usize> = {
Cell::new(rand::thread_rng().gen())
});

SEED.with(|seed| {
let s = seed.get();
seed.set(s.wrapping_add(1));
Self(s)
})
}
}

impl core::hash::BuildHasher for FxBuildHasherInner {
type Hasher = rustc_hash::FxHasher;

#[inline]
fn build_hasher(&self) -> Self::Hasher {
rustc_hash::FxHasher::with_seed(self.0)
}
}
use rustc_hash::FxRandomState as FxBuildHasherInner;
} else {
use rustc_hash::FxBuildHasher as FxBuildHasherInner;
}
Expand All @@ -115,7 +82,7 @@ cfg_if! {

// Default hasher.
cfg_if! {
// TODO: Use `foldhash` in zkVM when it's supported.
// TODO: Use `foldhash` in zkVM when it's supported. https://github.com/orlp/foldhash/issues/13
if #[cfg(all(feature = "map-foldhash", not(target_os = "zkvm")))] {
type DefaultHashBuilderInner = foldhash::fast::RandomState;
} else if #[cfg(feature = "map-fxhash")] {
Expand Down

0 comments on commit 0fdb0b5

Please sign in to comment.