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.
This commit is contained in:
haydonryan 2026-09-01 14:07:30 -05:00 • committed by Victoria Brekenfeld
parent 0f56d214b9
commit f61c0f9f76

View file

@ -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::<HashSet<_>>()
.symmetric_difference(&last_state.keys().collect::<HashSet<_>>())
.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,