mirror of https://github.com/helix-editor/helix
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. |
||
---|---|---|
.. | ||
src | ||
tests | ||
.gitignore | ||
Cargo.toml | ||
build.rs |