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

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

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

@ -1,8 +1,7 @@
use helix_view::editor::{WhitespacePalette, WhitespaceRender, WhitespaceRenderValue};
use helix_core::str_utils::char_to_byte_idx; 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 { pub enum WhitespaceKind {
None, None,
Space, Space,
@ -13,7 +12,7 @@ pub enum WhitespaceKind {
} }
impl 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 { match self {
WhitespaceKind::Space => &palette.space, WhitespaceKind::Space => &palette.space,
WhitespaceKind::NonBreakingSpace => &palette.nbsp, WhitespaceKind::NonBreakingSpace => &palette.nbsp,
@ -36,7 +35,7 @@ pub struct TrailingWhitespaceTracker {
} }
impl TrailingWhitespaceTracker { impl TrailingWhitespaceTracker {
pub fn new(render: &WhitespaceRender, palette: WhitespacePalette) -> Self { pub fn new(render: WhitespaceRender, palette: WhitespacePalette) -> Self {
Self { Self {
palette, palette,
enabled: render.any(WhitespaceRenderValue::Trailing), enabled: render.any(WhitespaceRenderValue::Trailing),
@ -124,7 +123,7 @@ mod tests {
fn test_trailing_whitespace_tracker_correctly_tracks_sequences() { fn test_trailing_whitespace_tracker_correctly_tracks_sequences() {
let ws_render = WhitespaceRender::Basic(WhitespaceRenderValue::Trailing); 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(5, WhitespaceKind::Space);
sut.track(6, WhitespaceKind::NonBreakingSpace); sut.track(6, WhitespaceKind::NonBreakingSpace);

Loading…
Cancel
Save