@@ -2135,11 +2135,14 @@ where
21352135 let mesh_n_high = self . config . mesh_n_high_for_topic ( topic_hash) ;
21362136 let mesh_outbound_min = self . config . mesh_outbound_min_for_topic ( topic_hash) ;
21372137
2138- // drop all peers with negative score, without PX
2139- // if there is at some point a stable retain method for BTreeSet the following can be
2140- // written more efficiently with retain.
2141- let mut to_remove_peers = Vec :: new ( ) ;
2142- for peer_id in peers. iter ( ) {
2138+ #[ cfg( feature = "metrics" ) ]
2139+ let mut removed_peers_count = 0 ;
2140+
2141+ // Drop all peers with negative score, without PX
2142+ //
2143+ // TODO: Use `extract_if` once MSRV is raised to a version that includes its
2144+ // stabilization.
2145+ peers. retain ( |peer_id| {
21432146 let peer_score = scores. get ( peer_id) . map ( |r| r. score ) . unwrap_or_default ( ) ;
21442147
21452148 // Record the score per mesh
@@ -2159,17 +2162,20 @@ where
21592162 let current_topic = to_prune. entry ( * peer_id) . or_insert_with ( Vec :: new) ;
21602163 current_topic. push ( topic_hash. clone ( ) ) ;
21612164 no_px. insert ( * peer_id) ;
2162- to_remove_peers. push ( * peer_id) ;
2165+
2166+ #[ cfg( feature = "metrics" ) ]
2167+ {
2168+ removed_peers_count += 1 ;
2169+ }
2170+
2171+ return false ;
21632172 }
2164- }
2173+ true
2174+ } ) ;
21652175
21662176 #[ cfg( feature = "metrics" ) ]
21672177 if let Some ( m) = self . metrics . as_mut ( ) {
2168- m. peers_removed ( topic_hash, Churn :: BadScore , to_remove_peers. len ( ) )
2169- }
2170-
2171- for peer_id in to_remove_peers {
2172- peers. remove ( & peer_id) ;
2178+ m. peers_removed ( topic_hash, Churn :: BadScore , removed_peers_count)
21732179 }
21742180
21752181 // too little peers - add some
0 commit comments