From f1890465e05348712fca50394d3844092af4e407 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 11 Mar 2026 14:17:49 +0100 Subject: [PATCH] globals: optimize expose_new_singletons --- src/globals.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/globals.rs b/src/globals.rs index aabb986c..07c18464 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -83,6 +83,7 @@ use { arrayvec::ArrayVec, linearize::{Linearize, StaticMap}, std::{ + cell::Cell, error::Error, fmt::{Display, Formatter}, rc::Rc, @@ -256,6 +257,7 @@ pub struct Globals { pub outputs: CopyHashMap>, pub seats: CopyHashMap>, singletons: StaticMap, + exposed: StaticMap>, } impl Globals { @@ -267,6 +269,7 @@ impl Globals { outputs: Default::default(), seats: Default::default(), singletons: StaticMap::from_fn(|_| GlobalName(0)), + exposed: Default::default(), }; add_singletons(&mut slf); slf @@ -407,13 +410,17 @@ impl Globals { pub fn expose_new_singletons(&self, state: &State) { let mut singletons = ArrayVec::<_, { Singleton::LENGTH }>::new(); - for name in self.singletons.values() { - if let Some(global) = self.registry.get(name) - && global.exposed(state) - { - singletons.push(global); + for (singleton, name) in self.singletons.iter() { + if let Some(global) = self.registry.get(name) { + let exposed = global.exposed(state); + if self.exposed[singleton].replace(exposed) != exposed && exposed { + singletons.push(global); + } } } + if singletons.is_empty() { + return; + } for client in state.clients.clients.borrow().values() { let client = &client.data; let caps = client.effective_caps.get();