#![feature(default_type_params)]
#![warn(unnecessary_qualification, non_uppercase_statics,
variant_size_difference, managed_heap_memory, unnecessary_typecast,
- missing_doc, unused_result, deprecated_owned_vector)]
+ missing_doc, unused_result)]
#[cfg(test)]
extern crate test;
///
/// Values containing non-static references are not permitted.
pub struct AnyMap {
- data: HashMap<TypeId, Box<Any>:'static, TypeIdHasher>,
+ data: HashMap<TypeId, Box<Any>, TypeIdHasher>,
}
impl AnyMap {
/// Set the value contained in the map for the type `T`.
/// This will override any previous value stored.
pub fn insert<T: 'static>(&mut self, value: T) {
- self.data.insert(TypeId::of::<T>(), box value as Box<Any>:'static);
+ self.data.insert(TypeId::of::<T>(), box value as Box<Any>);
}
/// Remove the value for the type `T` if it existed.
fn bench_insertion(b: &mut ::test::Bencher) {
b.iter(|| {
let mut data = AnyMap::new();
- data.insert(42i);
+ for _ in range(0, 100) {
+ data.insert(42i);
+ }
})
}
fn bench_find_missing(b: &mut ::test::Bencher) {
b.iter(|| {
let data = AnyMap::new();
- assert_eq!(data.find(), None::<&int>);
+ for _ in range(0, 100) {
+ assert_eq!(data.find(), None::<&int>);
+ }
})
}
b.iter(|| {
let mut data = AnyMap::new();
data.insert(42i);
- assert_eq!(data.find(), Some(&42i));
+ // These inner loops are a feeble attempt to drown the other factors.
+ for _ in range(0, 100) {
+ assert_eq!(data.find(), Some(&42i));
+ }
})
}