From 11c3ba935041437d11e1105dfa37480f2d27a6c4 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Wed, 12 Jan 2022 10:22:16 +0900 Subject: 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%. --- helix-term/src/ui/editor.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'helix-term') 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, -- cgit v1.2.3-70-g09d2