Skip to content

Commit 728f9e8

Browse files
committed
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: rust-lang/rust#86161 (comment)
2 parents dbd6dbe + 1437931 commit 728f9e8

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
allocator_api,
2222
slice_ptr_get,
2323
nonnull_slice_from_raw_parts,
24-
maybe_uninit_array_assume_init
24+
maybe_uninit_array_assume_init,
25+
build_hasher_simple_hash_one
2526
)
2627
)]
2728
#![allow(

src/map.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ where
242242
move |x| k.eq(x.borrow())
243243
}
244244

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

259+
#[cfg(feature = "nightly")]
260+
#[cfg_attr(feature = "inline-more", inline)]
261+
pub(crate) fn make_hash<K, Q, S>(hash_builder: &S, val: &Q) -> u64
262+
where
263+
K: Borrow<Q>,
264+
Q: Hash + ?Sized,
265+
S: BuildHasher,
266+
{
267+
hash_builder.hash_one(val)
268+
}
269+
270+
#[cfg(not(feature = "nightly"))]
258271
#[cfg_attr(feature = "inline-more", inline)]
259272
pub(crate) fn make_insert_hash<K, S>(hash_builder: &S, val: &K) -> u64
260273
where
@@ -267,6 +280,16 @@ where
267280
state.finish()
268281
}
269282

283+
#[cfg(feature = "nightly")]
284+
#[cfg_attr(feature = "inline-more", inline)]
285+
pub(crate) fn make_insert_hash<K, S>(hash_builder: &S, val: &K) -> u64
286+
where
287+
K: Hash,
288+
S: BuildHasher,
289+
{
290+
hash_builder.hash_one(val)
291+
}
292+
270293
#[cfg(feature = "ahash")]
271294
impl<K, V> HashMap<K, V, DefaultHashBuilder> {
272295
/// Creates an empty `HashMap`.
@@ -4793,8 +4816,6 @@ mod test_map {
47934816
#[test]
47944817
#[cfg(feature = "raw")]
47954818
fn test_into_iter_refresh() {
4796-
use core::hash::{BuildHasher, Hash, Hasher};
4797-
47984819
#[cfg(miri)]
47994820
const N: usize = 32;
48004821
#[cfg(not(miri))]
@@ -4817,9 +4838,7 @@ mod test_map {
48174838
loop {
48184839
// occasionally remove some elements
48194840
if i < n && rng.gen_bool(0.1) {
4820-
let mut hasher = hash_builder.build_hasher();
4821-
i.hash(&mut hasher);
4822-
let hash_value = hasher.finish();
4841+
let hash_value = super::make_insert_hash(&hash_builder, &i);
48234842

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

0 commit comments

Comments
 (0)