udp: TorrentMap cleaning: improve code, do less work

This commit is contained in:
Joakim Frostegård 2022-04-14 17:44:34 +02:00
parent 0f6be84576
commit ebe612a560

View file

@ -98,9 +98,9 @@ impl TorrentMaps {
let num_leechers = &mut torrent.num_leechers; let num_leechers = &mut torrent.num_leechers;
torrent.peers.retain(|_, peer| { torrent.peers.retain(|_, peer| {
let keep = peer.valid_until.0 > now; if peer.valid_until.0 > now {
true
if !keep { } else {
match peer.status { match peer.status {
PeerStatus::Seeding => { PeerStatus::Seeding => {
*num_seeders -= 1; *num_seeders -= 1;
@ -110,14 +110,18 @@ impl TorrentMaps {
} }
_ => (), _ => (),
}; };
}
keep false
}
}); });
if torrent.peers.is_empty() {
false
} else {
torrent.peers.shrink_to_fit(); torrent.peers.shrink_to_fit();
!torrent.peers.is_empty() true
}
} }
} }