diff options
author | Blaž Hrastnik | 2022-01-17 07:28:56 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-03-17 00:29:47 +0000 |
commit | 59f05088b9628086b35631338e49ae8f061dcba2 (patch) | |
tree | b8e87e318e2194a9473aca0ce799a4e32bffa33a /helix-term/src | |
parent | c6bd105484fbaf35812dddc41b8fb32cb054fc54 (diff) |
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%.
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/ui/editor.rs | 7 |
1 files changed, 3 insertions, 4 deletions
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) => { |