Skip to content

Commit

Permalink
optimize clear_expired_entries
Browse files Browse the repository at this point in the history
  • Loading branch information
shamardy committed Sep 30, 2024
1 parent 1c38da7 commit da884fc
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mm2src/common/expirable_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ impl<K: Eq + Hash + Clone, V> ExpirableMap<K, V> {

/// Removes expired entries from the map.
fn clear_expired_entries(&mut self) {
let keys_to_remove: Vec<_> = self
.expiries
.range(..=Instant::now())
.map(|(exp, key)| (*exp, key.clone()))
.collect();
for (exp, key) in keys_to_remove {
let now = Instant::now();

while let Some((exp, key)) = self.expiries.pop_first() {
if exp > now {
self.expiries.insert(exp, key);
break;
}
self.map.remove(&key);
self.expiries.remove(&exp);
}
}
}
Expand Down

0 comments on commit da884fc

Please sign in to comment.