From 7c85f92e31771b89f109f2e069eb8d0fea56bbdb Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 4 Apr 2023 18:04:40 +0200 Subject: [PATCH] refactor(gossipsub): use `pop` instead of `remove` Doesn't change any functionality but `pop` returns an `Option` whereas `remove` will panic on out-of-bounds. I am more comfortable with `pop` and a pattern match. Also, usage of `continue` allows us to not use an `else`. Pull-Request: #3734. --- protocols/gossipsub/src/handler.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 2c921286553..604803b874e 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -450,16 +450,16 @@ impl ConnectionHandler for Handler { ) { // outbound idle state Some(OutboundSubstreamState::WaitingOutput(substream)) => { - if !self.send_queue.is_empty() { - let message = self.send_queue.remove(0); + if let Some(message) = self.send_queue.pop() { self.send_queue.shrink_to_fit(); self.outbound_substream = Some(OutboundSubstreamState::PendingSend(substream, message)); - } else { - self.outbound_substream = - Some(OutboundSubstreamState::WaitingOutput(substream)); - break; + continue; } + + self.outbound_substream = + Some(OutboundSubstreamState::WaitingOutput(substream)); + break; } Some(OutboundSubstreamState::PendingSend(mut substream, message)) => { match Sink::poll_ready(Pin::new(&mut substream), cx) {