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
16 changes: 15 additions & 1 deletion crates/forktty-ui-gtk/src/gtk_app/terminal_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,26 @@ fn for_each_char_match_start(
if needle.is_empty() {
return;
}
// ⚑ Bolt: Fast path for case-insensitive search.
// Hoist target character's ASCII lower/upper conversions outside the loop.
// If the haystack character is ASCII, we can directly compare it against bounds.
let first_needle = needle[0];
let first_lower = first_needle.to_ascii_lowercase();
let first_upper = first_needle.to_ascii_uppercase();
Comment on lines +77 to +82

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 Document the search performance change

This commit presents a measurable user-visible speedup for searches over large scrollback buffers, but CHANGELOG.md still has an empty Unreleased section, so the improvement will be absent from the next release notes. Add an Unreleased entry describing the optimized terminal search behavior.

AGENTS.md reference: AGENTS.md:L183-L183

Useful? React with πŸ‘Β / πŸ‘Ž.

// Only enable the ASCII fast-path if the needle itself is ASCII.
// If the needle is non-ASCII (e.g. Kelvin sign \u{212A}), it might still case-fold
// to an ASCII character, so we must fall back to full Unicode matching.
let can_fast_path = first_needle.is_ascii();
let mut index = 0;
while index + needle.len() <= haystack.len() {
// Fast-path: short-circuit the full substring check if the first character
// doesn't match, avoiding iterator overhead in the common case.
if !chars_eq_ignore_case(haystack[index], first_needle) {
let h = haystack[index];
if can_fast_path && h.is_ascii() && h != first_lower && h != first_upper {
index += 1;
continue;
}
if !chars_eq_ignore_case(h, first_needle) {
index += 1;
continue;
}
Expand Down
43 changes: 43 additions & 0 deletions patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sys

with open("crates/forktty-ui-gtk/src/gtk_app/terminal_search.rs", "r") as f:
Comment on lines +1 to +3

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 the one-off patch script

This is an unused implementation artifact: a repository-wide search finds no caller, and running it only performs an unchecked textual rewrite of terminal_search.rs that is already present in this commit. Keeping it at the repository root creates a misleading mutation entry point unrelated to the build or test workflow; remove it rather than shipping it.

AGENTS.md reference: AGENTS.md:L122-L124

Useful? React with πŸ‘Β / πŸ‘Ž.

text = f.read()

search = """
let first_needle = needle[0];
let first_lower = first_needle.to_ascii_lowercase();
let first_upper = first_needle.to_ascii_uppercase();
let mut index = 0;
while index + needle.len() <= haystack.len() {
// Fast-path: short-circuit the full substring check if the first character
// doesn't match, avoiding iterator overhead in the common case.
let h = haystack[index];
if h.is_ascii() && h != first_lower && h != first_upper {
index += 1;
continue;
}
"""

replace = r"""
let first_needle = needle[0];
let first_lower = first_needle.to_ascii_lowercase();
let first_upper = first_needle.to_ascii_uppercase();
// Only enable the ASCII fast-path if the needle itself is ASCII.
// If the needle is non-ASCII (e.g. Kelvin sign \u{212A}), it might still case-fold
// to an ASCII character, so we must fall back to full Unicode matching.
let can_fast_path = first_needle.is_ascii();
let mut index = 0;
while index + needle.len() <= haystack.len() {
// Fast-path: short-circuit the full substring check if the first character
// doesn't match, avoiding iterator overhead in the common case.
let h = haystack[index];
if can_fast_path && h.is_ascii() && h != first_lower && h != first_upper {
index += 1;
continue;
}
"""

text = text.replace(search.strip(), replace.strip())

with open("crates/forktty-ui-gtk/src/gtk_app/terminal_search.rs", "w") as f:
f.write(text)
Loading