Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use BuildHasher::hash_one when feature = "nightly" is enabled. #292

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
allocator_api,
slice_ptr_get,
nonnull_slice_from_raw_parts,
maybe_uninit_array_assume_init
maybe_uninit_array_assume_init,
build_hasher_simple_hash_one
)
)]
#![allow(
Expand Down
29 changes: 24 additions & 5 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ where
move |x| k.eq(x.borrow())
}

#[cfg(not(feature = "nightly"))]
#[cfg_attr(feature = "inline-more", inline)]
pub(crate) fn make_hash<K, Q, S>(hash_builder: &S, val: &Q) -> u64
where
Expand All @@ -255,6 +256,18 @@ where
state.finish()
}

#[cfg(feature = "nightly")]
#[cfg_attr(feature = "inline-more", inline)]
pub(crate) fn make_hash<K, Q, S>(hash_builder: &S, val: &Q) -> u64
where
K: Borrow<Q>,
Q: Hash + ?Sized,
S: BuildHasher,
{
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
Expand All @@ -267,6 +280,16 @@ where
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 @@ -4793,8 +4816,6 @@ mod test_map {
#[test]
#[cfg(feature = "raw")]
fn test_into_iter_refresh() {
use core::hash::{BuildHasher, Hash, Hasher};

#[cfg(miri)]
const N: usize = 32;
#[cfg(not(miri))]
Expand All @@ -4817,9 +4838,7 @@ mod test_map {
loop {
// occasionally remove some elements
if i < n && rng.gen_bool(0.1) {
let mut hasher = hash_builder.build_hasher();
i.hash(&mut hasher);
let hash_value = hasher.finish();
let hash_value = super::make_insert_hash(&hash_builder, &i);

unsafe {
let e = map.table.find(hash_value, |q| q.0.eq(&i));
Expand Down