Browse Source

split_off channged to retain

This changes `split_off`, which does one allocation and copies `n` items
in the best case, `2 * n` items in the worst case to `retain`, which does
zero allocations and copies zero items in the best case and `3 * (n - 1)`
items in worst case (because swap is 3 copies and `retain` has to swap
due to possibility of panic).

I believe this should be net-benefit due to usually small `n`.
android-patches
Martin Habovstiak 5 years ago
committed by Roman Zeyde
parent
commit
669a4b829d
No known key found for this signature in database GPG Key ID: 87CAE5FA46917CBB
  1. 9
      src/rpc.rs

9
src/rpc.rs

@ -497,14 +497,15 @@ impl RPC {
let mut senders = senders.lock().unwrap(); let mut senders = senders.lock().unwrap();
match msg { match msg {
Notification::Periodic => { Notification::Periodic => {
for sender in senders.split_off(0) { senders.retain(|sender| {
if let Err(TrySendError::Disconnected(_)) = if let Err(TrySendError::Disconnected(_)) =
sender.try_send(Message::PeriodicUpdate) sender.try_send(Message::PeriodicUpdate)
{ {
continue; false // drop disconnected clients
} else {
true
} }
senders.push(sender); })
}
} }
Notification::Exit => acceptor.send(None).unwrap(), // mark acceptor as done Notification::Exit => acceptor.send(None).unwrap(), // mark acceptor as done
} }

Loading…
Cancel
Save