Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2023-10-27 - [Avoid redundant clone during iterator evaluation in recursive structure]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove one-off .jules repo metadata

This adds a Jules task-learning note under a new top-level .jules/ directory. The root AGENTS.md repo-shape guidance says to keep root docs stable and to “Prefer adding a new top-level directory only for a durable category of repo content” (AGENTS.md:106-117); this file is task-specific agent metadata rather than a durable ForkTTY content category, so it violates that contract and leaves one-off automation artifacts in the repository. Please drop it or move any durable guidance into an existing scoped source-of-truth doc.

Useful? React with 👍 / 👎.

**Learning:** When searching recursively in a tree-like structure (e.g. `PaneTree` using `PaneNode`), passing string or collection ownership via `.clone()` to an iterator predicate like `.any()` leads to unnecessary allocations. The condition may fail in multiple children, resulting in an O(N) allocation overhead just to verify a negative match.
**Action:** When passing parameters that eventually need to be owned inside nested traversal functions, pass them as references through the call stack and invoke `.clone()` only at the exact point of true insertion/ownership.
2 changes: 1 addition & 1 deletion crates/forktty-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions crates/forktty-core/src/model/pane_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: &SurfaceId,
) -> 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.clone());
*active = tabs.len() - 1;
true
} else {
Expand All @@ -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)),
}
}
13 changes: 5 additions & 8 deletions crates/forktty-ui-gtk/src/gtk_app/terminal_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,11 @@ pub(super) fn translate_gtk_key(
return Some(TerminalInput::Bytes(text.as_bytes().to_vec()));
}
}
if let Some(ch) = key.to_unicode() {
GhosttyKeySpec {
key: GhosttyKey::Char(ch),
ctrl,
alt,
}
} else {
return None;
let ch = key.to_unicode()?;
GhosttyKeySpec {
key: GhosttyKey::Char(ch),
ctrl,
alt,
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions crates/forktty-ui-gtk/src/socket_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ use help::{
use hooks::event::*;
#[cfg(test)]
use hooks::handle_hooks;
#[cfg(feature = "gtk-ghostty")]
#[allow(unused_imports)]
pub(crate) use hooks::hook_setup_reminder_message;
#[cfg(test)]
use hooks::install::*;
Expand Down
3 changes: 3 additions & 0 deletions crates/forktty-ui-gtk/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct TelemetryStamp {
last_ping_date: String,
}

#[allow(dead_code)]
pub fn maybe_start_anonymous_ping(config: &forktty_core::AppConfig) {
maybe_start_anonymous_ping_with(config, telemetry_stamp_path(), now_unix_seconds(), true);
}
Expand Down Expand Up @@ -50,12 +51,14 @@ fn maybe_start_anonymous_ping_with(
});
}

#[allow(dead_code)]
fn telemetry_stamp_path() -> Option<PathBuf> {
dirs::state_dir()
.or_else(dirs::data_local_dir)
.map(|base| base.join("forktty").join(TELEMETRY_STAMP_FILE))
}

#[allow(dead_code)]
fn now_unix_seconds() -> i64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
Expand Down
Loading