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 @@
## 2024-07-27 - [Avoid String allocations in eq checks]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove the one-off .jules root directory

This commit creates a new top-level directory solely for a three-line, tool-specific optimization note rather than a durable repository content category. Keeping this generated task artifact permanently expands the repository structure without owning product or build behavior; remove it rather than adding a new root bucket.

AGENTS.md reference: AGENTS.md:L131-L131

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

**Learning:** In Rust, `str::to_lowercase()` eagerly allocates a new `String`. This is bad for simple checks against fixed ASCII strings like `"true"` or `"yes"`.
**Action:** Use `.eq_ignore_ascii_case()` directly on the borrowed string slice to avoid allocation.
8 changes: 5 additions & 3 deletions crates/forktty-ui-gtk/src/socket_cli/hooks/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,11 @@ pub(in crate::socket_cli) fn hook_debug(context: &CliContext, message: &str) {
}

pub(in crate::socket_cli) fn is_truthy_env(key: &str) -> bool {
trimmed_env(key)
.map(|value| matches!(value.to_lowercase().as_str(), "1" | "true" | "yes"))
.unwrap_or(false)
// ⚑ Bolt optimization: Avoid eager `String` allocation from `.to_lowercase()`
// by using `eq_ignore_ascii_case` on the borrowed slice. Also simplify `map/unwrap_or` to `is_some_and`.
trimmed_env(key).is_some_and(|value| {
value == "1" || value.eq_ignore_ascii_case("true") || value.eq_ignore_ascii_case("yes")
})
}

/// Hook event ordering must survive wall-clock steps (NTP, manual `date`):
Expand Down
Loading