From a86a7d6920c03cff8d87d734fc72034d119ecda2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Vinyals=20Valdepe=C3=B1as?= Date: Sun, 14 Apr 2024 08:16:21 +0200 Subject: [PATCH] Small enum, faster to pass by value than borrowing it. --- helix-term/src/ui/document.rs | 2 +- helix-term/src/ui/trailing_whitespace.rs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/helix-term/src/ui/document.rs b/helix-term/src/ui/document.rs index 77b4b704b..e3af3a385 100644 --- a/helix-term/src/ui/document.rs +++ b/helix-term/src/ui/document.rs @@ -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, diff --git a/helix-term/src/ui/trailing_whitespace.rs b/helix-term/src/ui/trailing_whitespace.rs index ad30a5130..96c9d93b2 100644 --- a/helix-term/src/ui/trailing_whitespace.rs +++ b/helix-term/src/ui/trailing_whitespace.rs @@ -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);