on master help sign in
Optimize rendering by using Ropey::byte_slice
59f0508Blaž Hrastnik
Cargo.lock+8−2
@@ -862,10 +862,10 @@ checksum = "8c31b5c4033f8fdde8700e4657be2c497e7288f01515be52168c631e2e4d4086"
862[[package]]
862[[package]]
863name = "ropey"
863name = "ropey"
864version = "1.3.2"
864version = "1.3.2"
865−source = "registry+https://github.com/rust-lang/crates.io-index"
865+source = "git+https://github.com/cessen/ropey#38531e083f8cf5c5b1aeb328361895fb5a9b867c"
866−checksum = "e6b9aa65bcd9f308d37c7158b4a1afaaa32b8450213e20c9b98e7d5b3cc2fec3"
867dependencies = [
866dependencies = [
868 "smallvec",
867 "smallvec",
868+ "str_indices",
869]
869]
870
870
871[[package]]
871[[package]]
@@ -1031,6 +1031,12 @@ version = "1.0.5"
1031source = "registry+https://github.com/rust-lang/crates.io-index"
1031source = "registry+https://github.com/rust-lang/crates.io-index"
1032checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a"
1032checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a"
1033
1033
1034+[[package]]
1035+name = "str_indices"
1036+version = "0.3.1"
1037+source = "registry+https://github.com/rust-lang/crates.io-index"
1038+checksum = "283baa48c486e4c5e27b4d92c435db9eaceac236a74dab5e3293570e2c3fa4aa"
1039+
1034[[package]]
1040[[package]]
1035name = "syn"
1041name = "syn"
1036version = "1.0.88"
1042version = "1.0.88"
helix-core/Cargo.toml+2−1
@@ -15,7 +15,8 @@ include = ["src/**/*", "README.md"]
15[dependencies]
15[dependencies]
16helix-loader = { version = "0.6", path = "../helix-loader" }
16helix-loader = { version = "0.6", path = "../helix-loader" }
17
17
18−ropey = "1.3"
18+# ropey = "1.3"
19+ropey = { git = "https://github.com/cessen/ropey" }
19smallvec = "1.8"
20smallvec = "1.8"
20smartstring = "1.0.0"
21smartstring = "1.0.0"
21unicode-segmentation = "1.9"
22unicode-segmentation = "1.9"
helix-core/src/graphemes.rs+1−4
@@ -333,10 +333,7 @@ impl<'a> Iterator for RopeGraphemes<'a> {
333 }
333 }
334
334
335 if a < self.cur_chunk_start {
335 if a < self.cur_chunk_start {
336− let a_char = self.text.byte_to_char(a);
336+ Some(self.text.byte_slice(a..b))
337− let b_char = self.text.byte_to_char(b);
338−
339− Some(self.text.slice(a_char..b_char))
340 } else {
337 } else {
341 let a2 = a - self.cur_chunk_start;
338 let a2 = a - self.cur_chunk_start;
342 let b2 = b - self.cur_chunk_start;
339 let b2 = b - self.cur_chunk_start;
helix-core/src/syntax.rs+2−6
@@ -576,9 +576,7 @@ pub struct Syntax {
576}
576}
577
577
578fn byte_range_to_str(range: std::ops::Range<usize>, source: RopeSlice) -> Cow<str> {
578fn byte_range_to_str(range: std::ops::Range<usize>, source: RopeSlice) -> Cow<str> {
579− let start_char = source.byte_to_char(range.start);
580− let end_char = source.byte_to_char(range.end);
581− Cow::from(source.slice(start_char..end_char))
579+ Cow::from(source.byte_slice(range))
582}
580}
583
581
584impl Syntax {
582impl Syntax {
@@ -1197,9 +1195,7 @@ impl<'a> TextProvider<'a> for RopeProvider<'a> {
1197 type I = ChunksBytes<'a>;
1195 type I = ChunksBytes<'a>;
1198
1196
1199 fn text(&mut self, node: Node) -> Self::I {
1197 fn text(&mut self, node: Node) -> Self::I {
1200− let start_char = self.0.byte_to_char(node.start_byte());
1198+ let fragment = self.0.byte_slice(node.start_byte()..node.end_byte());
1201− let end_char = self.0.byte_to_char(node.end_byte());
1202− let fragment = self.0.slice(start_char..end_char);
1203 ChunksBytes {
1199 ChunksBytes {
1204 chunks: fragment.chunks(),
1200 chunks: fragment.chunks(),
1205 }
1201 }
helix-term/src/ui/editor.rs+3−4
@@ -183,6 +183,7 @@ impl EditorView {
183 .highlight_iter(text.slice(..), Some(range), None)
183 .highlight_iter(text.slice(..), Some(range), None)
184 .map(|event| event.unwrap())
184 .map(|event| event.unwrap())
185 .map(move |event| match event {
185 .map(move |event| match event {
186+ // TODO: use byte slices directly
186 // convert byte offsets to char offset
187 // convert byte offsets to char offset
187 HighlightEvent::Source { start, end } => {
188 HighlightEvent::Source { start, end } => {
188 let start =
189 let start =
@@ -317,6 +318,8 @@ impl EditorView {
317 theme: &Theme,
318 theme: &Theme,
318 highlights: H,
319 highlights: H,
319 ) {
320 ) {
321+ // It's slightly more efficient to produce a full RopeSlice from the Rope, then slice that a bunch
322+ // of times than it is to always call Rope::slice/get_slice (it will internally always hit RSEnum::Light).
320 let text = doc.text().slice(..);
323 let text = doc.text().slice(..);
321
324
322 let mut spans = Vec::new();
325 let mut spans = Vec::new();
@@ -327,10 +330,6 @@ impl EditorView {
327
330
328 let text_style = theme.get("ui.text");
331 let text_style = theme.get("ui.text");
329
332
330− // It's slightly more efficient to produce a full RopeSlice from the Rope, then slice that a bunch
331− // of times than it is to always call Rope::slice/get_slice (it will internally always hit RSEnum::Light).
332− let text = text.slice(..);
333−
334 'outer: for event in highlights {
333 'outer: for event in highlights {
335 match event {
334 match event {
336 HighlightEvent::HighlightStart(span) => {
335 HighlightEvent::HighlightStart(span) => {