more functional
This commit is contained in:
parent
40f5ea4007
commit
aad49cb19f
@ -510,21 +510,18 @@ impl KeyDirectory {
|
|||||||
cache_usage.drain(..untracked_usages);
|
cache_usage.drain(..untracked_usages);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cache = self.cache.borrow_mut();
|
if self.cache.borrow().len() <= MAX_CACHE_USAGE_TRACK { return; }
|
||||||
if cache.len() <= MAX_CACHE_USAGE_TRACK { return; }
|
|
||||||
|
|
||||||
let uniqs: HashSet<&Uuid> = cache_usage.iter().collect();
|
let uniqs: HashSet<&Uuid> = cache_usage.iter().collect();
|
||||||
let mut removes = HashSet::new();
|
let removes: Vec<Uuid> = {
|
||||||
|
let cache = self.cache.borrow();
|
||||||
for key in cache.keys() {
|
cache.keys().cloned().filter(|key| !uniqs.contains(key)).collect()
|
||||||
if !uniqs.contains(key) {
|
};
|
||||||
removes.insert(key.clone());
|
for key in removes {
|
||||||
|
self.cache.borrow_mut().remove(&key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for removed_key in removes { cache.remove(&removed_key); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reports how many keys are currently cached.
|
/// Reports how many keys are currently cached.
|
||||||
pub fn cache_size(&self) -> usize {
|
pub fn cache_size(&self) -> usize {
|
||||||
self.cache.borrow().len()
|
self.cache.borrow().len()
|
||||||
|
Loading…
Reference in New Issue
Block a user