From 1a57c28bc68c619f9d09b7d6dbd82497c3cb8537 Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Tue, 27 Apr 2021 12:43:23 +0800 Subject: [PATCH] Work with hashbrown 0.11.2 --- Cargo.toml | 4 ++-- src/map.rs | 42 +++++++++--------------------------------- src/raw/mod.rs | 2 +- 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 96938b3..3e97182 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,9 @@ categories = ["data-structures", "no-std"] [dependencies] # For the default hasher -ahash_ = { version = "0.6.1", default-features = false, optional = true, package = "ahash" } +ahash_ = { version = "0.7.0", default-features = false, optional = true, package = "ahash" } -hashbrown = { version = "0.9.1", default-features = false, features = ["raw"] } +hashbrown = { version = "0.11.2", default-features = false, features = ["raw"] } # For external trait impls rayon_ = { version = "1.0", optional = true, package = "rayon" } diff --git a/src/map.rs b/src/map.rs index 0f722f0..42254de 100644 --- a/src/map.rs +++ b/src/map.rs @@ -254,20 +254,10 @@ where Q: Hash + ?Sized, S: BuildHasher, { - #[cfg(feature = "ahash")] - { - //This enables specialization to improve performance on primitive types - use ahash_::CallHasher; - let state = hash_builder.build_hasher(); - Q::get_hash(val, state) - } - #[cfg(not(feature = "ahash"))] - { - use core::hash::Hasher; - let mut state = hash_builder.build_hasher(); - val.hash(&mut state); - state.finish() - } + use core::hash::Hasher; + let mut state = hash_builder.build_hasher(); + val.hash(&mut state); + state.finish() } #[cfg_attr(feature = "inline-more", inline)] @@ -276,20 +266,10 @@ where K: Hash, S: BuildHasher, { - #[cfg(feature = "ahash")] - { - //This enables specialization to improve performance on primitive types - use ahash_::CallHasher; - let state = hash_builder.build_hasher(); - K::get_hash(val, state) - } - #[cfg(not(feature = "ahash"))] - { - use core::hash::Hasher; - let mut state = hash_builder.build_hasher(); - val.hash(&mut state); - state.finish() - } + use core::hash::Hasher; + let mut state = hash_builder.build_hasher(); + val.hash(&mut state); + state.finish() } #[cfg(feature = "ahash")] @@ -4385,11 +4365,7 @@ mod test_map { let mut map: HashMap<_, _> = xs.iter().cloned().collect(); let compute_hash = |map: &HashMap, k: i32| -> u64 { - use core::hash::{BuildHasher, Hash, Hasher}; - - let mut hasher = map.hasher().build_hasher(); - k.hash(&mut hasher); - hasher.finish() + super::make_insert_hash::(map.hasher(), &k) }; // Existing key (insert) diff --git a/src/raw/mod.rs b/src/raw/mod.rs index 7a9009d..9019820 100644 --- a/src/raw/mod.rs +++ b/src/raw/mod.rs @@ -472,7 +472,7 @@ impl RawTable { #[cold] #[inline(never)] fn grow(&mut self, extra: usize) { - if let Err(_) = self.try_grow(extra, false) { + if self.try_grow(extra, false).is_err() { unsafe { core::hint::unreachable_unchecked() }; } }