Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Small tab group performance improvements (#41885)
tidely2a713c546b80
diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rsindex 7bd0daf56a4..75600a9ee1b 100644--- a/crates/gpui/src/app.rs+++ b/crates/gpui/src/app.rs@@ -316,6 +316,7 @@ impl SystemWindowTabController {.find_map(|(group, tabs)| tabs.iter().find(|tab| tab.id == id).map(|_| group));let current_group = current_group?;+ // TODO: `.keys()` returns arbitrary order, what does "next" mean?let mut group_ids: Vec<_> = controller.tab_groups.keys().collect();let idx = group_ids.iter().position(|g| *g == current_group)?;let next_idx = (idx + 1) % group_ids.len();@@ -340,6 +341,7 @@ impl SystemWindowTabController {.find_map(|(group, tabs)| tabs.iter().find(|tab| tab.id == id).map(|_| group));let current_group = current_group?;+ // TODO: `.keys()` returns arbitrary order, what does "previous" mean?let mut group_ids: Vec<_> = controller.tab_groups.keys().collect();let idx = group_ids.iter().position(|g| *g == current_group)?;let prev_idx = if idx == 0 {@@ -361,12 +363,9 @@ impl SystemWindowTabController {/// Get all tabs in the same window.pub fn tabs(&self, id: WindowId) -> Option<&Vec<SystemWindowTab>> {- let tab_group = self- .tab_groups- .iter()- .find_map(|(group, tabs)| tabs.iter().find(|tab| tab.id == id).map(|_| *group))?;-- self.tab_groups.get(&tab_group)+ self.tab_groups+ .values()+ .find(|tabs| tabs.iter().any(|tab| tab.id == id))}/// Initialize the visibility of the system window tab controller.@@ -441,7 +440,7 @@ impl SystemWindowTabController {/// Insert a tab into a tab group.pub fn add_tab(cx: &mut App, id: WindowId, tabs: Vec<SystemWindowTab>) {let mut controller = cx.global_mut::<SystemWindowTabController>();- let Some(tab) = tabs.clone().into_iter().find(|tab| tab.id == id) else {+ let Some(tab) = tabs.iter().find(|tab| tab.id == id).cloned() else {return;};@@ -504,16 +503,14 @@ impl SystemWindowTabController {return;};+ let initial_tabs_len = initial_tabs.len();let mut all_tabs = initial_tabs.clone();- for tabs in controller.tab_groups.values() {- all_tabs.extend(- tabs.iter()- .filter(|tab| !initial_tabs.contains(tab))- .cloned(),- );++ for (_, mut tabs) in controller.tab_groups.drain() {+ tabs.retain(|tab| !all_tabs[..initial_tabs_len].contains(tab));+ all_tabs.extend(tabs);}- controller.tab_groups.clear();controller.tab_groups.insert(0, all_tabs);}