From 279381ad3bea10c6a055097364bdad6bbc3e6cfc Mon Sep 17 00:00:00 2001 From: Marcelo Diop-Gonzalez Date: Wed, 22 Mar 2023 17:08:54 -0400 Subject: [PATCH 1/2] time: clean up redundant check in Wheel::poll() The condition checked in the and_then() call is the same as is checked in the match below, so we can clean it up by just matching on next_expiration() directly. --- tokio/src/runtime/time/wheel/mod.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tokio/src/runtime/time/wheel/mod.rs b/tokio/src/runtime/time/wheel/mod.rs index c3ba3643305..102c623b937 100644 --- a/tokio/src/runtime/time/wheel/mod.rs +++ b/tokio/src/runtime/time/wheel/mod.rs @@ -148,16 +148,7 @@ impl Wheel { return Some(handle); } - // under what circumstances is poll.expiration Some vs. None? - let expiration = self.next_expiration().and_then(|expiration| { - if expiration.deadline > now { - None - } else { - Some(expiration) - } - }); - - match expiration { + match self.next_expiration() { Some(ref expiration) if expiration.deadline > now => return None, Some(ref expiration) => { self.process_expiration(expiration); From fdd9b6ffd2fbabcc02b2322e80d83f02f171e7b3 Mon Sep 17 00:00:00 2001 From: Marcelo Diop-Gonzalez Date: Wed, 22 Mar 2023 18:42:49 -0400 Subject: [PATCH 2/2] fix match statement arms --- tokio/src/runtime/time/wheel/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tokio/src/runtime/time/wheel/mod.rs b/tokio/src/runtime/time/wheel/mod.rs index 102c623b937..bf13b7b2415 100644 --- a/tokio/src/runtime/time/wheel/mod.rs +++ b/tokio/src/runtime/time/wheel/mod.rs @@ -149,13 +149,12 @@ impl Wheel { } match self.next_expiration() { - Some(ref expiration) if expiration.deadline > now => return None, - Some(ref expiration) => { + Some(ref expiration) if expiration.deadline <= now => { self.process_expiration(expiration); self.set_elapsed(expiration.deadline); } - None => { + _ => { // in this case the poll did not indicate an expiration // _and_ we were not able to find a next expiration in // the current list of timers. advance to the poll's