Skip to content

Commit

Permalink
Do not clone for ListenersEvent::Closed
Browse files Browse the repository at this point in the history
We would like to avoid clones where possible for efficiency reasons.
When returning a `ListenersEvent::Closed` we are already consuming the
listener (by way of a pin projection).  We can therefore use a consuming
iterator instead of cloning.

Use `drain(..).collect()` instead of clone to consume the addresses when
returning a `ListenersEvent::Closed`.
  • Loading branch information
tcharding committed Mar 12, 2020
1 parent 7e347a0 commit 2867fe8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/connection/listeners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,14 @@ where
Poll::Ready(None) => {
return Poll::Ready(ListenersEvent::Closed {
listener_id: *listener_project.id,
addresses: listener.addresses.to_vec(),
addresses: listener_project.addresses.drain(..).collect(),
reason: Ok(()),
})
}
Poll::Ready(Some(Err(err))) => {
return Poll::Ready(ListenersEvent::Closed {
listener_id: *listener_project.id,
addresses: listener.addresses.to_vec(),
addresses: listener_project.addresses.drain(..).collect(),
reason: Err(err),
})
}
Expand Down

0 comments on commit 2867fe8

Please sign in to comment.