From f61c0f9f76caa8640de4e2077ec31b6c37d12866 Mon Sep 17 00:00:00 2001 From: haydonryan Date: Tue, 1 Sep 2026 14:07:30 -0500 Subject: [PATCH] tabs: avoid two HashSet allocations in tab-change detection Replace the symmetric_difference over two freshly-materialized HashSets with direct contains_key lookups on the existing key sets. Semantically identical (set difference non-empty iff any key is in exactly one set) but removes two heap HashSet allocations plus hashing of every key on each widget update. Also drops the now-unused HashSet import. Implements compact-idiomatic-code-20 from the cosmic-comp optimization report. Created with the help of DeepSeek V4 Flash. --- src/shell/element/stack/tabs.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/shell/element/stack/tabs.rs b/src/shell/element/stack/tabs.rs index 86218db6..9dd5ef81 100644 --- a/src/shell/element/stack/tabs.rs +++ b/src/shell/element/stack/tabs.rs @@ -31,7 +31,7 @@ use keyframe::{ functions::{EaseInOutCubic, EaseOutCubic}, }; use std::{ - collections::{HashMap, HashSet, VecDeque}, + collections::{HashMap, VecDeque}, time::{Duration, Instant}, }; @@ -757,12 +757,10 @@ where state.last_state = Some(current_state.clone()); } let last_state = state.last_state.as_mut().unwrap(); - let unknown_keys = current_state - .keys() - .collect::>() - .symmetric_difference(&last_state.keys().collect::>()) - .next() - .is_some(); + let unknown_keys = current_state.len() != last_state.len() + || current_state + .keys() + .any(|key| !last_state.contains_key(key)); enum Difference { NewOrRemoved,