Auto merge of #292 - thomcc:nightly-hash-one, r=Amanieu

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

I describe why this is good for more than just convenience here: https://github.com/rust-lang/rust/issues/86161#issuecomment-916577133
This commit is contained in:
bors
2021-09-10 09:09:52 +00:00
2 changed files with 26 additions and 6 deletions
+2 -1
View File
@@ -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(
+24 -5
View File
@@ -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
@@ -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
@@ -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`.
@@ -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))]
@@ -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));