Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
rope: Implement `Rope::is_char_boundary` via chars bitmap (#40945)
Lukas Wirth044701e3a59e
diff --git a/crates/rope/src/chunk.rs b/crates/rope/src/chunk.rsindex 515ae8c7686..51904cd8e22 100644--- a/crates/rope/src/chunk.rs+++ b/crates/rope/src/chunk.rs@@ -93,6 +93,11 @@ impl Chunk {pub fn tabs(&self) -> Bitmap {self.tabs}++ #[inline(always)]+ pub fn is_char_boundary(&self, offset: usize) -> bool {+ (1 as Bitmap).unbounded_shl(offset as u32) & self.chars != 0 || offset == self.text.len()+ }}#[derive(Clone, Copy, Debug)]@@ -123,8 +128,8 @@ impl<'a> ChunkSlice<'a> {}#[inline(always)]- pub fn is_char_boundary(self, offset: usize) -> bool {- self.text.is_char_boundary(offset)+ pub fn is_char_boundary(&self, offset: usize) -> bool {+ (1 as Bitmap).unbounded_shl(offset as u32) & self.chars != 0 || offset == self.text.len()}#[inline(always)]diff --git a/crates/rope/src/rope.rs b/crates/rope/src/rope.rsindex c710ed86570..204b13cfae2 100644--- a/crates/rope/src/rope.rs+++ b/crates/rope/src/rope.rs@@ -44,7 +44,7 @@ impl Rope {}let (start, _, item) = self.chunks.find::<usize, _>((), &offset, Bias::Left);let chunk_offset = offset - start;- item.map(|chunk| chunk.text.is_char_boundary(chunk_offset))+ item.map(|chunk| chunk.is_char_boundary(chunk_offset)).unwrap_or(false)}