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/syntax.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'helix-core/src/syntax.rs') 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