From 6d0a64dcc97a1857f7e12be00189870860a68a3e Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Sat, 5 Mar 2016 12:58:19 +1100 Subject: [PATCH] Ungate efficient hashing (stable in Rust 1.7.0). --- src/lib.rs | 1 - src/raw.rs | 42 +++++------------------------------------- 2 files changed, 5 insertions(+), 38 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 64a0f6b..6eac7dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ //! This crate provides the `AnyMap` type, a safe and convenient store for one value of each type. -#![cfg_attr(feature = "unstable", feature(hashmap_hasher, raw))] #![cfg_attr(all(feature = "unstable", test), feature(test))] #![warn(missing_docs, unused_results)] diff --git a/src/raw.rs b/src/raw.rs index 3d1be50..445b137 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -5,38 +5,19 @@ use std::any::TypeId; use std::borrow::Borrow; use std::collections::hash_map::{self, HashMap}; -#[cfg(feature = "unstable")] -use std::collections::hash_state::HashState; use std::hash::Hash; -#[cfg(feature = "unstable")] -use std::hash::Hasher; -#[cfg(feature = "unstable")] +use std::hash::{Hasher, BuildHasherDefault}; use std::mem; use std::ops::{Index, IndexMut}; -#[cfg(feature = "unstable")] use std::ptr; use any::{Any, UncheckedAnyExt}; -#[cfg(feature = "unstable")] +#[derive(Default)] struct TypeIdHasher { value: u64, } -#[derive(Clone)] -#[cfg(feature = "unstable")] -struct TypeIdState; - -#[cfg(feature = "unstable")] -impl HashState for TypeIdState { - type Hasher = TypeIdHasher; - - fn hasher(&self) -> TypeIdHasher { - TypeIdHasher { value: 0 } - } -} - -#[cfg(feature = "unstable")] impl Hasher for TypeIdHasher { #[inline(always)] fn write(&mut self, bytes: &[u8]) { @@ -51,7 +32,6 @@ impl Hasher for TypeIdHasher { fn finish(&self) -> u64 { self.value } } - /// The raw, underlying form of a `Map`. /// /// At its essence, this is a wrapper around `HashMap>`, with the portions that @@ -61,11 +41,7 @@ impl Hasher for TypeIdHasher { /// doesn’t tend to be so very useful. Still, if you need it, it’s here. #[derive(Debug)] pub struct RawMap { - #[cfg(feature = "unstable")] - inner: HashMap, TypeIdState>, - - #[cfg(not(feature = "unstable"))] - inner: HashMap>, + inner: HashMap, BuildHasherDefault>, } // #[derive(Clone)] would want A to implement Clone, but in reality it’s only Box that can. @@ -83,18 +59,10 @@ impl Default for RawMap { } } -#[cfg(feature = "unstable")] -impl_common_methods! { - field: RawMap.inner; - new() => HashMap::with_hash_state(TypeIdState); - with_capacity(capacity) => HashMap::with_capacity_and_hash_state(capacity, TypeIdState); -} - -#[cfg(not(feature = "unstable"))] impl_common_methods! { field: RawMap.inner; - new() => HashMap::new(); - with_capacity(capacity) => HashMap::with_capacity(capacity); + new() => HashMap::with_hasher(Default::default()); + with_capacity(capacity) => HashMap::with_capacity_and_hasher(capacity, Default::default()); } /// RawMap iterator. -- 2.42.0