From 0613f12aeb4115ddd7a00811a91fb23e87441a2f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 10 Jul 2026 16:21:38 +0000 Subject: [PATCH] perf(core): avoid eager string allocations in push_tab_to_leaf Updates `push_tab_to_leaf` signature in `forktty-core` to take a `&str` instead of an owned `String` (`SurfaceId`), eliminating unnecessary `O(N)` string clones during recursive pane tree traversal and deferring allocation (`.to_owned()`) until the exact target leaf match is confirmed. Co-authored-by: Lucenx9 <185146821+Lucenx9@users.noreply.github.com> --- crates/forktty-core/src/model.rs | 2 +- crates/forktty-core/src/model/pane_tree.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/forktty-core/src/model.rs b/crates/forktty-core/src/model.rs index c86541a3..8b5761d9 100644 --- a/crates/forktty-core/src/model.rs +++ b/crates/forktty-core/src/model.rs @@ -906,7 +906,7 @@ impl WorkspaceModel { .workspaces .get_mut(&workspace_id) .expect("workspace verified above"); - if !push_tab_to_leaf(&mut workspace.pane_tree, near_surface_id, new_id.clone()) { + if !push_tab_to_leaf(&mut workspace.pane_tree, near_surface_id, &new_id) { return None; } workspace.focused_surface_id = new_id.clone(); diff --git a/crates/forktty-core/src/model/pane_tree.rs b/crates/forktty-core/src/model/pane_tree.rs index 2a3f7fc5..0c943e39 100644 --- a/crates/forktty-core/src/model/pane_tree.rs +++ b/crates/forktty-core/src/model/pane_tree.rs @@ -646,12 +646,12 @@ pub(super) fn set_leaf_active_for_surface(node: &mut PaneNode, surface_id: &str) pub(super) fn push_tab_to_leaf( node: &mut PaneNode, near_surface_id: &str, - new_tab_id: SurfaceId, + new_tab_id: &str, ) -> bool { match node { PaneNode::Leaf { tabs, active } => { if tabs.iter().any(|id| id == near_surface_id) { - tabs.push(new_tab_id); + tabs.push(new_tab_id.to_owned()); *active = tabs.len() - 1; true } else { @@ -660,6 +660,6 @@ pub(super) fn push_tab_to_leaf( } PaneNode::Split { children, .. } => children .iter_mut() - .any(|child| push_tab_to_leaf(child, near_surface_id, new_tab_id.clone())), + .any(|child| push_tab_to_leaf(child, near_surface_id, new_tab_id)), } }