Skip to content

Commit

Permalink
review fix: add implementation details to clear_expired_entries
Browse files Browse the repository at this point in the history
  • Loading branch information
shamardy committed Oct 2, 2024
1 parent 20fa7e5 commit d2675d2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mm2src/common/expirable_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ impl<K: Eq + Hash + Copy, V> ExpirableMap<K, V> {
}

/// Removes expired entries from the map.
///
/// Iterates through the `expiries` in order, removing entries that have expired.
/// Stops at the first non-expired entry, leveraging the sorted nature of `BTreeMap`.
///
/// # Implementation notes:
/// Why `pop_first()` usage is better than `first_key_value()` in this case:
///
/// - `pop_first()`: Removes expired entries efficiently without an extra remove operation.
/// - `first_key_value()`: Wouldn't require re-insertion for non-expired entries,
/// but `pop_first()` only needs to do this once per function call.
fn clear_expired_entries(&mut self) {
let now = Instant::now();

Expand Down

0 comments on commit d2675d2

Please sign in to comment.