Skip to content

Commit 7c85f92

Browse files
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.
1 parent 95fa913 commit 7c85f92

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

protocols/gossipsub/src/handler.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,16 @@ impl ConnectionHandler for Handler {
450450
) {
451451
// outbound idle state
452452
Some(OutboundSubstreamState::WaitingOutput(substream)) => {
453-
if !self.send_queue.is_empty() {
454-
let message = self.send_queue.remove(0);
453+
if let Some(message) = self.send_queue.pop() {
455454
self.send_queue.shrink_to_fit();
456455
self.outbound_substream =
457456
Some(OutboundSubstreamState::PendingSend(substream, message));
458-
} else {
459-
self.outbound_substream =
460-
Some(OutboundSubstreamState::WaitingOutput(substream));
461-
break;
457+
continue;
462458
}
459+
460+
self.outbound_substream =
461+
Some(OutboundSubstreamState::WaitingOutput(substream));
462+
break;
463463
}
464464
Some(OutboundSubstreamState::PendingSend(mut substream, message)) => {
465465
match Sink::poll_ready(Pin::new(&mut substream), cx) {

0 commit comments

Comments
 (0)