Skip to content

Commit

Permalink
Remove redundant make_insert_hash internal function
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed May 31, 2023
1 parent f552bdb commit bceae1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
37 changes: 7 additions & 30 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,29 +260,6 @@ where
hash_builder.hash_one(val)
}

#[cfg(not(feature = "nightly"))]
#[cfg_attr(feature = "inline-more", inline)]
pub(crate) fn make_insert_hash<K, S>(hash_builder: &S, val: &K) -> u64
where
K: Hash,
S: BuildHasher,
{
use core::hash::Hasher;
let mut state = hash_builder.build_hasher();
val.hash(&mut state);
state.finish()
}

#[cfg(feature = "nightly")]
#[cfg_attr(feature = "inline-more", inline)]
pub(crate) fn make_insert_hash<K, S>(hash_builder: &S, val: &K) -> u64
where
K: Hash,
S: BuildHasher,
{
hash_builder.hash_one(val)
}

#[cfg(feature = "ahash")]
impl<K, V> HashMap<K, V, DefaultHashBuilder> {
/// Creates an empty `HashMap`.
Expand Down Expand Up @@ -1262,7 +1239,7 @@ where
/// ```
#[cfg_attr(feature = "inline-more", inline)]
pub fn entry(&mut self, key: K) -> Entry<'_, K, V, S, A> {
let hash = make_insert_hash::<K, S>(&self.hash_builder, &key);
let hash = make_hash::<K, S>(&self.hash_builder, &key);
if let Some(elem) = self.table.find(hash, equivalent_key(&key)) {
Entry::Occupied(OccupiedEntry {
hash,
Expand Down Expand Up @@ -1782,7 +1759,7 @@ where
/// ```
#[cfg_attr(feature = "inline-more", inline)]
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
let hash = make_insert_hash::<K, S>(&self.hash_builder, &k);
let hash = make_hash::<K, S>(&self.hash_builder, &k);
let hasher = make_hasher::<_, V, S>(&self.hash_builder);
match self
.table
Expand Down Expand Up @@ -1849,7 +1826,7 @@ where
/// ```
#[cfg_attr(feature = "inline-more", inline)]
pub fn insert_unique_unchecked(&mut self, k: K, v: V) -> (&K, &mut V) {
let hash = make_insert_hash::<K, S>(&self.hash_builder, &k);
let hash = make_hash::<K, S>(&self.hash_builder, &k);
let bucket = self
.table
.insert(hash, (k, v), make_hasher::<_, V, S>(&self.hash_builder));
Expand Down Expand Up @@ -4003,7 +3980,7 @@ impl<'a, K, V, S, A: Allocator + Clone> RawVacantEntryMut<'a, K, V, S, A> {
K: Hash,
S: BuildHasher,
{
let hash = make_insert_hash::<K, S>(self.hash_builder, &key);
let hash = make_hash::<K, S>(self.hash_builder, &key);
self.insert_hashed_nocheck(hash, key, value)
}

Expand Down Expand Up @@ -4111,7 +4088,7 @@ impl<'a, K, V, S, A: Allocator + Clone> RawVacantEntryMut<'a, K, V, S, A> {
K: Hash,
S: BuildHasher,
{
let hash = make_insert_hash::<K, S>(self.hash_builder, &key);
let hash = make_hash::<K, S>(self.hash_builder, &key);
let elem = self.table.insert(
hash,
(key, value),
Expand Down Expand Up @@ -8194,7 +8171,7 @@ mod test_map {
let mut map: HashMap<_, _> = xs.iter().copied().collect();

let compute_hash = |map: &HashMap<i32, i32>, k: i32| -> u64 {
super::make_insert_hash::<i32, _>(map.hasher(), &k)
super::make_hash::<i32, _>(map.hasher(), &k)
};

// Existing key (insert)
Expand Down Expand Up @@ -8356,7 +8333,7 @@ mod test_map {
loop {
// occasionally remove some elements
if i < n && rng.gen_bool(0.1) {
let hash_value = super::make_insert_hash(&hash_builder, &i);
let hash_value = super::make_hash(&hash_builder, &i);

unsafe {
let e = map.table.find(hash_value, |q| q.0.eq(&i));
Expand Down
4 changes: 2 additions & 2 deletions src/rustc_entry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use self::RustcEntry::*;
use crate::map::{make_insert_hash, Drain, HashMap, IntoIter, Iter, IterMut};
use crate::map::{make_hash, Drain, HashMap, IntoIter, Iter, IterMut};
use crate::raw::{Allocator, Bucket, Global, RawTable};
use core::fmt::{self, Debug};
use core::hash::{BuildHasher, Hash};
Expand Down Expand Up @@ -32,7 +32,7 @@ where
/// ```
#[cfg_attr(feature = "inline-more", inline)]
pub fn rustc_entry(&mut self, key: K) -> RustcEntry<'_, K, V, A> {
let hash = make_insert_hash(&self.hash_builder, &key);
let hash = make_hash(&self.hash_builder, &key);
if let Some(elem) = self.table.find(hash, |q| q.0.eq(&key)) {
RustcEntry::Occupied(RustcOccupiedEntry {
key: Some(key),
Expand Down

0 comments on commit bceae1e

Please sign in to comment.