Skip to content

Commit

Permalink
timers: short-cut timeout extension pattern
Browse files Browse the repository at this point in the history
in case we constantly extend the same timer the
head might already point to the timer we want
to cancel. in this case we can directly remove the
timer to reduce building up the heap unnecessarily.
  • Loading branch information
cmeissl committed Jun 8, 2024
1 parent 89d2703 commit da82365
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/sources/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ impl TimerWheel {
}

pub(crate) fn cancel(&mut self, counter: u32) {
if self
.heap
.peek()
.map(|data| data.counter == counter)
.unwrap_or(false)
{
self.heap.pop();
return;
};

self.heap
.iter()
.find(|data| data.counter == counter)
Expand Down

0 comments on commit da82365

Please sign in to comment.