Use FxHashMap
and FxHashSet
in hot code paths
We can also use these maps and sets in place of `SeaHasher` because they are also deterministic. Note that we're not swapping std's `HashMap` and `HashSet` wholesale inside of `collections` because on the server we need cryptographically secure collections.
This commit is contained in:
parent
385c830bef
commit
b871f906d6
8 changed files with 40 additions and 52 deletions
|
@ -9,7 +9,7 @@ path = "src/collections.rs"
|
|||
doctest = false
|
||||
|
||||
[features]
|
||||
test-support = ["seahash"]
|
||||
test-support = []
|
||||
|
||||
[dependencies]
|
||||
seahash = { version = "4.1", optional = true }
|
||||
rustc-hash = "1.1"
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
#[cfg(feature = "test-support")]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct DeterministicState;
|
||||
pub type HashMap<K, V> = FxHashMap<K, V>;
|
||||
|
||||
#[cfg(feature = "test-support")]
|
||||
impl std::hash::BuildHasher for DeterministicState {
|
||||
type Hasher = seahash::SeaHasher;
|
||||
|
||||
fn build_hasher(&self) -> Self::Hasher {
|
||||
seahash::SeaHasher::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-support")]
|
||||
pub type HashMap<K, V> = std::collections::HashMap<K, V, DeterministicState>;
|
||||
|
||||
#[cfg(feature = "test-support")]
|
||||
pub type HashSet<T> = std::collections::HashSet<T, DeterministicState>;
|
||||
pub type HashSet<T> = FxHashSet<T>;
|
||||
|
||||
#[cfg(not(feature = "test-support"))]
|
||||
pub type HashMap<K, V> = std::collections::HashMap<K, V>;
|
||||
|
@ -23,6 +10,7 @@ pub type HashMap<K, V> = std::collections::HashMap<K, V>;
|
|||
#[cfg(not(feature = "test-support"))]
|
||||
pub type HashSet<T> = std::collections::HashSet<T>;
|
||||
|
||||
pub use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use std::any::TypeId;
|
||||
pub use std::collections::*;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue