HashMap::retain

This commit is contained in:
Tomasz Drwięga 2017-11-13 17:09:30 +01:00
parent 72907da2ae
commit 8b85f648ca
No known key found for this signature in database
GPG Key ID: D066F497E62CAF66

View File

@ -57,10 +57,7 @@ impl Reservations {
/// The reserved nonce cannot be smaller than the minimal nonce. /// The reserved nonce cannot be smaller than the minimal nonce.
pub fn reserve(&mut self, sender: Address, minimal: U256) -> Reserved { pub fn reserve(&mut self, sender: Address, minimal: U256) -> Reserved {
if self.nonces.len() + 1 > Self::CLEAN_AT { if self.nonces.len() + 1 > Self::CLEAN_AT {
let to_remove = self.nonces.iter().filter(|&(_, v)| v.is_empty()).map(|(k, _)| *k).collect::<Vec<_>>(); self.nonces.retain(|_, v| !v.is_empty());
for address in to_remove {
self.nonces.remove(&address);
}
} }
let pool = &self.pool; let pool = &self.pool;