diff options
Diffstat (limited to 'components/util')
-rw-r--r-- | components/util/cache.rs | 3 | ||||
-rw-r--r-- | components/util/smallvec.rs | 21 |
2 files changed, 20 insertions, 4 deletions
diff --git a/components/util/cache.rs b/components/util/cache.rs index 03bd649f777..35390d309bf 100644 --- a/components/util/cache.rs +++ b/components/util/cache.rs @@ -6,6 +6,7 @@ use std::collections::HashMap; use std::collections::hash_map::{Occupied, Vacant}; use rand::Rng; use std::hash::{Hash, sip}; +use std::iter::repeat; use std::rand::task_rng; use std::slice::Items; @@ -148,7 +149,7 @@ impl<K:Clone+PartialEq+Hash,V:Clone> SimpleHashCache<K,V> { pub fn new(cache_size: uint) -> SimpleHashCache<K,V> { let mut r = task_rng(); SimpleHashCache { - entries: Vec::from_elem(cache_size, None), + entries: repeat(None).take(cache_size).collect(), k0: r.gen(), k1: r.gen(), } diff --git a/components/util/smallvec.rs b/components/util/smallvec.rs index 60e22f25a70..e92d3d3eeba 100644 --- a/components/util/smallvec.rs +++ b/components/util/smallvec.rs @@ -531,7 +531,10 @@ pub mod tests { let mut v = SmallVec16::new(); v.push("hello".into_string()); v.push("there".into_string()); - assert_eq!(v.as_slice(), vec!["hello".into_string(), "there".into_string()].as_slice()); + assert_eq!(v.as_slice(), vec![ + "hello".into_string(), + "there".into_string(), + ].as_slice()); } #[test] @@ -541,7 +544,12 @@ pub mod tests { v.push("there".into_string()); v.push("burma".into_string()); v.push("shave".into_string()); - assert_eq!(v.as_slice(), vec!["hello".into_string(), "there".into_string(), "burma".into_string(), "shave".into_string()].as_slice()); + assert_eq!(v.as_slice(), vec![ + "hello".into_string(), + "there".into_string(), + "burma".into_string(), + "shave".into_string(), + ].as_slice()); } #[test] @@ -556,7 +564,14 @@ pub mod tests { v.push("burma".into_string()); v.push("shave".into_string()); assert_eq!(v.as_slice(), vec![ - "hello".into_string(), "there".into_string(), "burma".into_string(), "shave".into_string(), "hello".into_string(), "there".into_string(), "burma".into_string(), "shave".into_string(), + "hello".into_string(), + "there".into_string(), + "burma".into_string(), + "shave".into_string(), + "hello".into_string(), + "there".into_string(), + "burma".into_string(), + "shave".into_string(), ].as_slice()); } } |