From 781478d73dd3dfe42596e1dd370339ca6ad30e31 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Thu, 11 Jan 2024 18:47:06 -0800 Subject: Optimize for ASCII case in floor/ceil_grapheme. --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 0dfe335..c5ea852 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,7 @@ fn floor_grapheme_cluster( line: &Rope, offset: usize, ) -> Result> { - if offset == 0 || offset == line.len() { + if offset == 0 || offset == line.len() || line.byte(offset) < 128 { return Ok(offset); } let mut offset = line.floor_char_boundary(offset); @@ -101,6 +101,9 @@ fn ceil_grapheme_cluster( offset: usize, ) -> Result> { let mut offset = line.ceil_char_boundary(offset); + if offset == line.len() || line.byte(offset) < 128 { + return Ok(offset); + } write!(stdout(), "\x1b[G")?; line.slice(0, offset).print(&mut stdout())?; let (_, target_col) = term::cursor_pos(stdin)?; -- cgit v1.3.1