adding shrink-to-fit
This commit is contained in:
parent
a4f03100e9
commit
c5edf237b2
@ -542,6 +542,8 @@ impl KeyDirectory {
|
||||
if removes.is_empty() { return; }
|
||||
let mut cache = self.cache.write().unwrap();
|
||||
for key in removes { cache.remove(&key); }
|
||||
|
||||
cache.shrink_to_fit();
|
||||
}
|
||||
|
||||
/// Reports how many keys are currently cached.
|
||||
|
@ -273,13 +273,16 @@ impl SecretStore {
|
||||
|
||||
/// Makes account unlocks expire and removes unused key files from memory
|
||||
pub fn collect_garbage(&mut self) {
|
||||
let mut garbage_lock = self.unlocks.write().unwrap();
|
||||
self.directory.collect_garbage();
|
||||
let utc = UTC::now();
|
||||
let expired_addresses = self.unlocks.read().unwrap().iter()
|
||||
let expired_addresses = garbage_lock.iter()
|
||||
.filter(|&(_, unlock)| unlock.expires < utc)
|
||||
.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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user