From 59f05088b9628086b35631338e49ae8f061dcba2 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 17 Jan 2022 16:28:56 +0900 Subject: Optimize rendering by using Ropey::byte_slice This avoids costly conversions via byte_to_char (which are then reversed back into bytes internally in Ropey). Reduces time spent in slice/byte_to_char from ~24% to ~5%. --- helix-term/src/ui/editor.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 31a9bfc8..2b9de5d6 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -183,6 +183,7 @@ impl EditorView { .highlight_iter(text.slice(..), Some(range), None) .map(|event| event.unwrap()) .map(move |event| match event { + // TODO: use byte slices directly // convert byte offsets to char offset HighlightEvent::Source { start, end } => { let start = @@ -317,6 +318,8 @@ impl EditorView { theme: &Theme, highlights: H, ) { + // It's slightly more efficient to produce a full RopeSlice from the Rope, then slice that a bunch + // of times than it is to always call Rope::slice/get_slice (it will internally always hit RSEnum::Light). let text = doc.text().slice(..); let mut spans = Vec::new(); @@ -327,10 +330,6 @@ impl EditorView { let text_style = theme.get("ui.text"); - // It's slightly more efficient to produce a full RopeSlice from the Rope, then slice that a bunch - // of times than it is to always call Rope::slice/get_slice (it will internally always hit RSEnum::Light). - let text = text.slice(..); - 'outer: for event in highlights { match event { HighlightEvent::HighlightStart(span) => { -- cgit v1.2.3-70-g09d2