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.
This commit is contained in:
Thomas Eizinger 2023-04-04 18:04:40 +02:00 committed by GitHub
parent 95fa913923
commit 7c85f92e31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -450,17 +450,17 @@ 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 {
continue;
}
self.outbound_substream =
Some(OutboundSubstreamState::WaitingOutput(substream));
break;
}
}
Some(OutboundSubstreamState::PendingSend(mut substream, message)) => {
match Sink::poll_ready(Pin::new(&mut substream), cx) {
Poll::Ready(Ok(())) => {