From d332eb4570175b1d16146ab45bbfbd5b7ce55844 Mon Sep 17 00:00:00 2001 From: cjwcommuny Date: Thu, 6 Oct 2022 13:26:20 +0800 Subject: [PATCH] remove unnecessary `Option` for `mio::Events` in `tokio::runtime::io::Driver` --- tokio/src/runtime/io/mod.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tokio/src/runtime/io/mod.rs b/tokio/src/runtime/io/mod.rs index aa9447322ef..96bb9a4c2a8 100644 --- a/tokio/src/runtime/io/mod.rs +++ b/tokio/src/runtime/io/mod.rs @@ -27,7 +27,7 @@ pub(crate) struct Driver { tick: u8, /// Reuse the `mio::Events` value across calls to poll. - events: Option, + events: mio::Events, /// Primary slab handle containing the state for each resource registered /// with this driver. @@ -119,7 +119,7 @@ impl Driver { Ok(Driver { tick: 0, - events: Some(mio::Events::with_capacity(1024)), + events: mio::Events::with_capacity(1024), poll, resources: slab, inner: Arc::new(Inner { @@ -173,7 +173,7 @@ impl Driver { self.resources.compact() } - let mut events = self.events.take().expect("i/o driver event store missing"); + let mut events = &mut self.events; // Block waiting for an event to happen, peeling out how many events // happened. @@ -194,27 +194,23 @@ impl Driver { let token = event.token(); if token != TOKEN_WAKEUP { - self.dispatch(token, Ready::from_mio(event)); + Self::dispatch(&mut self.resources, self.tick, token, Ready::from_mio(event)); ready_count += 1; } } self.inner.metrics.incr_ready_count_by(ready_count); - - self.events = Some(events); } - fn dispatch(&mut self, token: mio::Token, ready: Ready) { + fn dispatch(resources: &mut Slab, tick: u8, token: mio::Token, ready: Ready) { let addr = slab::Address::from_usize(ADDRESS.unpack(token.0)); - let resources = &mut self.resources; - let io = match resources.get(addr) { Some(io) => io, None => return, }; - let res = io.set_readiness(Some(token.0), Tick::Set(self.tick), |curr| curr | ready); + let res = io.set_readiness(Some(token.0), Tick::Set(tick), |curr| curr | ready); if res.is_err() { // token no longer valid!