mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +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 {
|
fn find_or_create(&mut self, key: &K, blk: &fn(&K) -> V) -> V {
|
||||||
match self.entry {
|
match self.find(key) {
|
||||||
None => {
|
Some(value) => value,
|
||||||
|
None => {
|
||||||
let value = blk(key);
|
let value = blk(key);
|
||||||
self.entry = Some((key.clone(), value.clone()));
|
self.entry = Some((key.clone(), value.clone()));
|
||||||
value
|
value
|
||||||
},
|
}
|
||||||
Some((ref _k, ref v)) => v.clone()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,11 +58,9 @@ fn test_monocache() {
|
||||||
|
|
||||||
assert!(cache.find(&1).is_some());
|
assert!(cache.find(&1).is_some());
|
||||||
assert!(cache.find(&2).is_none());
|
assert!(cache.find(&2).is_none());
|
||||||
/* FIXME: clarify behavior here:
|
|
||||||
cache.find_or_create(&2, |_v| { two });
|
cache.find_or_create(&2, |_v| { two });
|
||||||
assert!(cache.find(&2).is_some());
|
assert!(cache.find(&2).is_some());
|
||||||
assert!(cache.find(&1).is_none());
|
assert!(cache.find(&1).is_none());
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HashCache<K, V> {
|
pub struct HashCache<K, V> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue