adding shrink-to-fit

This commit is contained in:
Nikolay Volf 2016-03-13 19:52:37 +01:00
parent a4f03100e9
commit c5edf237b2
2 changed files with 7 additions and 2 deletions

View File

@ -542,6 +542,8 @@ impl KeyDirectory {
if removes.is_empty() { return; } if removes.is_empty() { return; }
let mut cache = self.cache.write().unwrap(); let mut cache = self.cache.write().unwrap();
for key in removes { cache.remove(&key); } for key in removes { cache.remove(&key); }
cache.shrink_to_fit();
} }
/// Reports how many keys are currently cached. /// Reports how many keys are currently cached.

View File

@ -273,13 +273,16 @@ impl SecretStore {
/// Makes account unlocks expire and removes unused key files from memory /// Makes account unlocks expire and removes unused key files from memory
pub fn collect_garbage(&mut self) { pub fn collect_garbage(&mut self) {
let mut garbage_lock = self.unlocks.write().unwrap();
self.directory.collect_garbage(); self.directory.collect_garbage();
let utc = UTC::now(); let utc = UTC::now();
let expired_addresses = self.unlocks.read().unwrap().iter() let expired_addresses = garbage_lock.iter()
.filter(|&(_, unlock)| unlock.expires < utc) .filter(|&(_, unlock)| unlock.expires < utc)
.map(|(address, _)| address.clone()).collect::<Vec<Address>>(); .map(|(address, _)| address.clone()).collect::<Vec<Address>>();
for expired in expired_addresses { self.unlocks.write().unwrap().remove(&expired); } for expired in expired_addresses { garbage_lock.remove(&expired); }
garbage_lock.shrink_to_fit();
} }
} }