mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Fix eviction in MonoCache::find_or_create
This commit is contained in:
parent
fc9fdf30a6
commit
5289d35145
1 changed files with 4 additions and 6 deletions
|
@ -34,13 +34,13 @@ impl<K: Clone + Eq, V: Clone> Cache<K,V> for MonoCache<K,V> {
|
|||
}
|
||||
|
||||
fn find_or_create(&mut self, key: &K, blk: &fn(&K) -> V) -> V {
|
||||
match self.entry {
|
||||
None => {
|
||||
match self.find(key) {
|
||||
Some(value) => value,
|
||||
None => {
|
||||
let value = blk(key);
|
||||
self.entry = Some((key.clone(), value.clone()));
|
||||
value
|
||||
},
|
||||
Some((ref _k, ref v)) => v.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,11 +58,9 @@ fn test_monocache() {
|
|||
|
||||
assert!(cache.find(&1).is_some());
|
||||
assert!(cache.find(&2).is_none());
|
||||
/* FIXME: clarify behavior here:
|
||||
cache.find_or_create(&2, |_v| { two });
|
||||
assert!(cache.find(&2).is_some());
|
||||
assert!(cache.find(&1).is_none());
|
||||
*/
|
||||
}
|
||||
|
||||
pub struct HashCache<K, V> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue