radicle/node: avoid unnecessary allocations in `Emitter::emit_all`
This commit is contained in:
parent
8b1d475170
commit
589925e3a3
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -228,15 +228,13 @@ impl<T: Clone> Emitter<T> {
|
|||
/// 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<T>) {
|
||||
pub fn emit_all(&self, events: impl IntoIterator<Item = T>) {
|
||||
// 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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue