more functional

This commit is contained in:
Nikolay Volf 2016-02-17 23:25:25 +03:00
parent 40f5ea4007
commit aad49cb19f

View File

@ -510,19 +510,16 @@ 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.