Chris Morgan
›
Git
›
anymap
› commitdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
patch
|
inline
| side by side (parent:
82f41ca
)
commit
grep
author
committer
pickaxe
?
search:
re
Ungate efficient hashing (stable in Rust 1.7.0).
author
Chris Morgan
<me@chrismorgan.info>
Sat, 5 Mar 2016 01:58:19 +0000
committer
Chris Morgan
<me@chrismorgan.info>
Sat, 5 Mar 2016 01:58:19 +0000
src/lib.rs
patch
|
blob
|
history
src/raw.rs
patch
|
blob
|
history
diff --git
a/src/lib.rs
b/src/lib.rs
index 64a0f6bebc69af1643679525ac9efa4bc4dc50a2..6eac7dc625b6c22bb3331ba67bfe574f428abd8b 100644
(file)
--- 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.
//! 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)]
#![cfg_attr(all(feature = "unstable", test), feature(test))]
#![warn(missing_docs, unused_results)]
diff --git
a/src/raw.rs
b/src/raw.rs
index 3d1be50333c1951af280cbeac78356cab0b6f3c9..445b137cb9beb7f83c1610a2fd60fa040d49a6ff 100644
(file)
--- 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};
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;
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};
use std::mem;
use std::ops::{Index, IndexMut};
-#[cfg(feature = "unstable")]
use std::ptr;
use any::{Any, UncheckedAnyExt};
use std::ptr;
use any::{Any, UncheckedAnyExt};
-#[
cfg(feature = "unstable"
)]
+#[
derive(Default
)]
struct TypeIdHasher {
value: u64,
}
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]) {
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 }
}
fn finish(&self) -> u64 { self.value }
}
-
/// The raw, underlying form of a `Map`.
///
/// At its essence, this is a wrapper around `HashMap<TypeId, Box<Any>>`, with the portions that
/// The raw, underlying form of a `Map`.
///
/// At its essence, this is a wrapper around `HashMap<TypeId, Box<Any>>`, 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<A: ?Sized + UncheckedAnyExt = Any> {
/// doesn’t tend to be so very useful. Still, if you need it, it’s here.
#[derive(Debug)]
pub struct RawMap<A: ?Sized + UncheckedAnyExt = Any> {
- #[cfg(feature = "unstable")]
- inner: HashMap<TypeId, Box<A>, TypeIdState>,
-
- #[cfg(not(feature = "unstable"))]
- inner: HashMap<TypeId, Box<A>>,
+ inner: HashMap<TypeId, Box<A>, BuildHasherDefault<TypeIdHasher>>,
}
// #[derive(Clone)] would want A to implement Clone, but in reality it’s only Box<A> that can.
}
// #[derive(Clone)] would want A to implement Clone, but in reality it’s only Box<A> that can.
@@
-83,18
+59,10
@@
impl<A: ?Sized + UncheckedAnyExt> Default for RawMap<A> {
}
}
}
}
-#[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;
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.
}
/// RawMap iterator.