Small enum, faster to pass by value than borrowing it.

pull/7215/head
Alexandre Vinyals Valdepeñas 7 months ago
parent ba893751c2
commit a86a7d6920

@ -398,7 +398,7 @@ impl<'a> TextRenderer<'a> {
let ws = &editor_config.whitespace;
let regular_ws = WhitespaceFeature::Regular.palette(ws, tab_width);
let trailing_ws = WhitespaceFeature::Trailing.palette(ws, tab_width);
let trailing_whitespace_tracker = TrailingWhitespaceTracker::new(&ws.render, trailing_ws);
let trailing_whitespace_tracker = TrailingWhitespaceTracker::new(ws.render, trailing_ws);
TextRenderer {
surface,

@ -1,8 +1,7 @@
use helix_view::editor::{WhitespacePalette, WhitespaceRender, WhitespaceRenderValue};
use helix_core::str_utils::char_to_byte_idx;
use helix_view::editor::{WhitespacePalette, WhitespaceRender, WhitespaceRenderValue};
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum WhitespaceKind {
None,
Space,
@ -13,7 +12,7 @@ pub enum WhitespaceKind {
}
impl WhitespaceKind {
pub fn to_str<'a>(&'a self, palette: &'a WhitespacePalette) -> &'a str {
pub fn to_str(self, palette: &WhitespacePalette) -> &str {
match self {
WhitespaceKind::Space => &palette.space,
WhitespaceKind::NonBreakingSpace => &palette.nbsp,
@ -36,7 +35,7 @@ pub struct TrailingWhitespaceTracker {
}
impl TrailingWhitespaceTracker {
pub fn new(render: &WhitespaceRender, palette: WhitespacePalette) -> Self {
pub fn new(render: WhitespaceRender, palette: WhitespacePalette) -> Self {
Self {
palette,
enabled: render.any(WhitespaceRenderValue::Trailing),
@ -124,7 +123,7 @@ mod tests {
fn test_trailing_whitespace_tracker_correctly_tracks_sequences() {
let ws_render = WhitespaceRender::Basic(WhitespaceRenderValue::Trailing);
let mut sut = TrailingWhitespaceTracker::new(&ws_render, palette());
let mut sut = TrailingWhitespaceTracker::new(ws_render, palette());
sut.track(5, WhitespaceKind::Space);
sut.track(6, WhitespaceKind::NonBreakingSpace);

Loading…
Cancel
Save