From fa05a309f3a1a371ca0f5f8df92ae97652d04f0e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 7 Jul 2016 12:17:13 +0200 Subject: [PATCH] Remove HashCache. --- components/util/cache.rs | 51 +--------------------------------------- tests/unit/util/cache.rs | 15 +----------- 2 files changed, 2 insertions(+), 64 deletions(-) diff --git a/components/util/cache.rs b/components/util/cache.rs index f446f43b498..63a2d403d4a 100644 --- a/components/util/cache.rs +++ b/components/util/cache.rs @@ -4,58 +4,9 @@ use rand; use rand::Rng; -use std::collections::HashMap; -use std::collections::hash_map::Entry::{Occupied, Vacant}; -use std::default::Default; -use std::hash::{BuildHasherDefault, Hash, Hasher, SipHasher}; +use std::hash::{Hash, Hasher, SipHasher}; use std::slice::Iter; - -#[derive(Debug)] -pub struct HashCache - where K: PartialEq + Eq + Hash, - V: Clone, -{ - entries: HashMap>, -} - -impl HashCache - where K: PartialEq + Eq + Hash, - V: Clone, -{ - pub fn new() -> HashCache { - HashCache { - entries: HashMap::with_hasher(Default::default()), - } - } - - pub fn insert(&mut self, key: K, value: V) { - self.entries.insert(key, value); - } - - pub fn find(&self, key: &K) -> Option { - match self.entries.get(key) { - Some(v) => Some(v.clone()), - None => None, - } - } - - pub fn find_or_create(&mut self, key: K, mut blk: F) -> V where F: FnMut() -> V { - match self.entries.entry(key) { - Occupied(occupied) => { - (*occupied.get()).clone() - } - Vacant(vacant) => { - (*vacant.insert(blk())).clone() - } - } - } - - pub fn evict_all(&mut self) { - self.entries.clear(); - } -} - pub struct LRUCache { entries: Vec<(K, V)>, cache_size: usize, diff --git a/tests/unit/util/cache.rs b/tests/unit/util/cache.rs index 9bb207622bd..a938cf638ce 100644 --- a/tests/unit/util/cache.rs +++ b/tests/unit/util/cache.rs @@ -3,20 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::cell::Cell; -use util::cache::{HashCache, LRUCache}; - -#[test] -fn test_hashcache() { - let mut cache: HashCache> = HashCache::new(); - - cache.insert(1, Cell::new("one")); - assert!(cache.find(&1).is_some()); - assert!(cache.find(&2).is_none()); - - cache.find_or_create(2, || { Cell::new("two") }); - assert!(cache.find(&1).is_some()); - assert!(cache.find(&2).is_some()); -} +use util::cache::LRUCache; #[test] fn test_lru_cache() {