From 7edc8935b6ad704f589023c275f852d1760dfbc1 Mon Sep 17 00:00:00 2001 From: Uncle Stinky Date: Wed, 27 Aug 2025 15:31:32 +0300 Subject: [PATCH] optimize offenders gathering with a single pass over the data Signed-off-by: Uncle Stinky --- pallets/slow-clap/Cargo.toml | 2 +- pallets/slow-clap/src/lib.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pallets/slow-clap/Cargo.toml b/pallets/slow-clap/Cargo.toml index 071a066..49c68f1 100644 --- a/pallets/slow-clap/Cargo.toml +++ b/pallets/slow-clap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-slow-clap" -version = "0.3.41" +version = "0.3.42" description = "Applause protocol for the EVM bridge" license.workspace = true authors.workspace = true diff --git a/pallets/slow-clap/src/lib.rs b/pallets/slow-clap/src/lib.rs index e49bb1f..f5b9f16 100644 --- a/pallets/slow-clap/src/lib.rs +++ b/pallets/slow-clap/src/lib.rs @@ -1123,11 +1123,13 @@ impl OneSessionHandler for Pallet { let offenders = validators .into_iter() .enumerate() - .filter(|(index, _)| !Self::is_good_actor(*index, median_claps, &claps_in_session)) - .filter_map(|(_, id)| { - >::IdentificationOf::convert( - id.clone(), - ).map(|full_id| (id, full_id)) + .filter_map(|(index, id)| { + (!Self::is_good_actor(index, median_claps, &claps_in_session)).then(|| { + >::IdentificationOf::convert( + id.clone(), + ).map(|full_id| (id, full_id)) + }) + .flatten() }) .collect::>>();