Skip to content

Commit

Permalink
refactor(gossipsub): use pop instead of remove
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomaseizinger authored Apr 4, 2023
1 parent 95fa913 commit 7c85f92
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions protocols/gossipsub/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7c85f92

Please sign in to comment.