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-core/src/graphemes.rs | 5 +---- helix-core/src/syntax.rs | 8 ++------ 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'helix-core/src') diff --git a/helix-core/src/graphemes.rs b/helix-core/src/graphemes.rs index aa898684..c0c61775 100644 --- a/helix-core/src/graphemes.rs +++ b/helix-core/src/graphemes.rs @@ -333,10 +333,7 @@ impl<'a> Iterator for RopeGraphemes<'a> { } if a < self.cur_chunk_start { - let a_char = self.text.byte_to_char(a); - let b_char = self.text.byte_to_char(b); - - Some(self.text.slice(a_char..b_char)) + Some(self.text.byte_slice(a..b)) } else { let a2 = a - self.cur_chunk_start; let b2 = b - self.cur_chunk_start; diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 3fc91efc..f76683b9 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -576,9 +576,7 @@ pub struct Syntax { } fn byte_range_to_str(range: std::ops::Range, source: RopeSlice) -> Cow { - let start_char = source.byte_to_char(range.start); - let end_char = source.byte_to_char(range.end); - Cow::from(source.slice(start_char..end_char)) + Cow::from(source.byte_slice(range)) } impl Syntax { @@ -1197,9 +1195,7 @@ impl<'a> TextProvider<'a> for RopeProvider<'a> { type I = ChunksBytes<'a>; fn text(&mut self, node: Node) -> Self::I { - let start_char = self.0.byte_to_char(node.start_byte()); - let end_char = self.0.byte_to_char(node.end_byte()); - let fragment = self.0.slice(start_char..end_char); + let fragment = self.0.byte_slice(node.start_byte()..node.end_byte()); ChunksBytes { chunks: fragment.chunks(), } -- cgit v1.2.3-70-g09d2