diff --git a/perf.data b/perf.data deleted file mode 100644 index c6423f17a71..00000000000 Binary files a/perf.data and /dev/null differ diff --git a/perf.data.old b/perf.data.old deleted file mode 100644 index 843ce9b8bfd..00000000000 Binary files a/perf.data.old and /dev/null differ diff --git a/perf.data.opt b/perf.data.opt deleted file mode 100644 index 96f02e803a8..00000000000 Binary files a/perf.data.opt and /dev/null differ diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index ec40a206e65..9b3e90272a3 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -924,8 +924,20 @@ mod tests { #[ignore] fn repoll_with_active_protocols() { fn run_benchmark(protcol_count: usize, iters: usize) { - const PROTOCOLS: &str = - "/a /b /c /d /e /f /g /h /i /j /k /l /m /n /o /p /q /r /s /t /u /v /w /x /y /z"; + // we need longer protocol names + macro_rules! protocols { + ($($name:ident)*) => { + concat!( + $( + "/", + stringify!($name), + "ffffffffffffffffffffff ", + )* + ) + } + } + + const PROTOCOLS: &str = protocols!(a b c d e f g h i j k l m n o p q r s t u v); let protocols = PROTOCOLS.split(' ').collect::>(); let mut connection = Connection::new( diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index a7576992144..15165b49c68 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -338,22 +338,31 @@ impl<'a> ProtocolsChange<'a> { temp_owner: &'a mut Vec, ) -> impl Iterator { temp_owner.clear(); - existing_protocols.values_mut().for_each(|v| *v = false); + // to avoid looping trough the map to just set the booleans we use the fact that all of + // the booleans in the map have same value + let valid_value = !existing_protocols.values().next().copied().unwrap_or(false); + let mut count = Some(existing_protocols.len()); for new_protocol in new_protocols { *existing_protocols .entry(AsStrHashEq(new_protocol)) .or_insert_with_key(|k| { temp_owner.extend(StreamProtocol::try_from_owned(k.0.as_ref().to_owned()).ok()); + count = None; false - }) = true; + }) = valid_value; + count = count.map(|c| c - 1); + } + + if count == Some(0) { + return None.into_iter().chain(None); } let added_count = temp_owner.len(); existing_protocols.retain(|k, v| { - if !*v { + if *v != valid_value { temp_owner.push(StreamProtocol::try_from_owned(k.0.as_ref().to_owned()).unwrap()); } - *v + *v == valid_value }); let (added, removed) = temp_owner.split_at(added_count);