helix/helix-term
Michael Davis 702b1d0a0f
statusline: Avoid unnecessary allocations for `&'static str` spans
Previously the statusline `write` function only accepted a string
and optional Style, so all rendering functions converted text to
strings. Some elements write spans with `&'static str`s, however, making
this unnecessary since `Span<'a>` is a wrapper around `Cow<'a, str>` and
style, and a `Span<'static>` would outlive all required lifetimes.

Moreover many elements could produce `Span<'a>` according to the
lifetime in `RenderContext` in the future, potentially re-borrowing from
the Editor borrow, so this change could save allocations for many
file-type elements (with more future changes). This is not explored in
this patch since the statusline functions currently add bespoke padding
per-element, but with a future refactor to make spacing consistent this
could be possible.

This change refactors the write function to accept a `Span<'a>` and
rewrites some related code to fit the codebase better (preferring `for`
to iterator's `for_each` for example). The new code is more complicated
lifetime-wise but avoids allocations in these cases:

* spacer for mode name when a pane is not focused
* LSP spinner frames
* '●' (workspace) diagnostic indicators
* " W " workspace diagnostic prefix
* file modification indicators
* read-only indicators
* spacer element

... and opens the door to avoid allocation for file name elements in the
future.
2025-05-15 08:33:02 -04:00
..
src statusline: Avoid unnecessary allocations for `&'static str` spans 2025-05-15 08:33:02 -04:00
tests syntax: Move config types to a separate module 2025-05-13 18:30:21 -04:00
.gitignore Initial import. 2020-05-20 18:14:51 +09:00
Cargo.toml build(deps): bump libc in the rust-dependencies group (#13389) 2025-04-22 15:10:48 +09:00
build.rs chore: clean up clippy lints (#11377) 2024-08-01 06:39:46 +09:00