From 589925e3a3d792b321661a2e3f33b1f38be15063 Mon Sep 17 00:00:00 2001 From: Defelo Date: Sat, 24 Jan 2026 17:40:13 +0100 Subject: [PATCH] radicle/node: avoid unnecessary allocations in `Emitter::emit_all` --- crates/radicle-protocol/src/service.rs | 12 +++++------- crates/radicle/src/node/events.rs | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/crates/radicle-protocol/src/service.rs b/crates/radicle-protocol/src/service.rs index 9baf4d9c..ad3f9d0c 100644 --- a/crates/radicle-protocol/src/service.rs +++ b/crates/radicle-protocol/src/service.rs @@ -1198,16 +1198,14 @@ where rid, updated: updated.clone(), }); - self.emitter.emit_all( - canonical - .into_iter() - .map(|(refname, target)| Event::CanonicalRefUpdated { + self.emitter + .emit_all(canonical.into_iter().map(|(refname, target)| { + Event::CanonicalRefUpdated { rid, refname, target, - }) - .collect(), - ); + } + })); // Announce our new inventory if this fetch was a full clone. // Only update and announce inventory for public repositories. diff --git a/crates/radicle/src/node/events.rs b/crates/radicle/src/node/events.rs index a8434c7b..01f7f968 100644 --- a/crates/radicle/src/node/events.rs +++ b/crates/radicle/src/node/events.rs @@ -228,15 +228,13 @@ impl Emitter { /// Emit a batch of events to subscribers and drop those who can't receive /// them. /// N.b. subscribers are also dropped if their channel is full. - pub fn emit_all(&self, events: Vec) { + pub fn emit_all(&self, events: impl IntoIterator) { // SAFETY: We deliberately propagate panics from other threads holding the lock. #[allow(clippy::unwrap_used)] - self.subscribers.lock().unwrap().retain(|s| { - events - .clone() - .into_iter() - .all(|event| s.try_send(event).is_ok()) - }); + let mut subscribers = self.subscribers.lock().unwrap(); + for event in events { + subscribers.retain(|s| s.try_send(event.clone()).is_ok()); + } } /// Subscribe to events stream.