From 4c2ea4966f03f15314a9fb6ef5dc2cb40386bc9e Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Sun, 28 Jan 2024 10:47:49 +0100 Subject: [PATCH] Inline PoolInner::reap() --- bb8/src/inner.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/bb8/src/inner.rs b/bb8/src/inner.rs index 5dc2a23..c0478ab 100644 --- a/bb8/src/inner.rs +++ b/bb8/src/inner.rs @@ -149,12 +149,6 @@ where self.inner.internals.lock().state() } - fn reap(&self) { - let mut internals = self.inner.internals.lock(); - let approvals = internals.reap(&self.inner.statics); - self.spawn_replenishing_approvals(approvals); - } - // Outside of Pool to avoid borrow splitting issues on self async fn add_connection(&self, approval: Approval) -> Result<(), M::Error> where @@ -238,11 +232,16 @@ impl Reaper { async fn run(mut self) { loop { let _ = self.interval.tick().await; - if let Some(inner) = self.pool.upgrade() { - PoolInner { inner }.reap(); - } else { - break; - } + let pool = match self.pool.upgrade() { + Some(inner) => PoolInner { inner }, + None => break, + }; + + let mut locked = pool.inner.internals.lock(); + let approvals = locked.reap(&pool.inner.statics); + drop(locked); + + pool.spawn_replenishing_approvals(approvals); } } }