From a75bea339712d5b9b42a2998d9c2d1d0d9c3f29d Mon Sep 17 00:00:00 2001 From: Brian Misiak Date: Mon, 26 Feb 2024 11:14:43 -0800 Subject: [PATCH] cleaner remove_timers --- src/scheduling.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/scheduling.rs b/src/scheduling.rs index 99b7305..fddf856 100644 --- a/src/scheduling.rs +++ b/src/scheduling.rs @@ -91,22 +91,18 @@ pub(crate) fn delete_timer(timer_key: usize) -> Result, BorrowMutE } pub(crate) fn remove_timers(predicate: impl Fn(&Timer) -> bool) { - let mut removed_timers = Vec::new(); - TIMERS.with_borrow_mut(|t| { - t.retain(|key, timer| { - if predicate(timer) { - removed_timers.push(key); - false - } else { - true - } + TIMERS.with_borrow_mut(|timers| { + QUEUE.with_borrow_mut(|queue| { + timers.retain(|key, timer| { + if predicate(timer) { + queue.remove(&key); + false + } else { + true + } + }); }); }); - QUEUE.with_borrow_mut(|q| { - for key in removed_timers { - q.remove(&key); - } - }); } fn deschedule_next_due(next_due: &NextDue) -> Result<(), TriggeringError> {