diff options
author | Blaž Hrastnik | 2022-01-12 01:22:16 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-01-23 07:04:12 +0000 |
commit | 11c3ba935041437d11e1105dfa37480f2d27a6c4 (patch) | |
tree | 4f498a51332cc86910917fd0d84fc91440852c1f /helix-term/src/ui | |
parent | 9d41113ae02665fd73a7e25b4aff9cc416cfe4ae (diff) |
Speed up ensure_next_boundary during render
This code:
let start = ensure_grapheme_boundary_next(text, text.byte_to_char(start));
let end = ensure_grapheme_boundary_next(text, text.byte_to_char(end));
Would convert byte to char index, but then internally immediately convert back
to byte index, operate on it, then convert it to char index.
This change reduces the amount of time spent in ensure_grapheme_boundary from
29% to 2%.
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/editor.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index acf6b8d8..956db72e 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -8,7 +8,9 @@ use crate::{ use helix_core::{ coords_at_pos, encoding, - graphemes::{ensure_grapheme_boundary_next, next_grapheme_boundary, prev_grapheme_boundary}, + graphemes::{ + ensure_grapheme_boundary_next_byte, next_grapheme_boundary, prev_grapheme_boundary, + }, movement::Direction, syntax::{self, HighlightEvent}, unicode::segmentation::UnicodeSegmentation, @@ -154,8 +156,8 @@ impl EditorView { .map(move |event| match event { // convert byte offsets to char offset HighlightEvent::Source { start, end } => { - let start = ensure_grapheme_boundary_next(text, text.byte_to_char(start)); - let end = ensure_grapheme_boundary_next(text, text.byte_to_char(end)); + let start = text.byte_to_char(ensure_grapheme_boundary_next_byte(text, start)); + let end = text.byte_to_char(ensure_grapheme_boundary_next_byte(text, end)); HighlightEvent::Source { start, end } } event => event, |