Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
rope: Minor optimization for tab indices (#20911)
Adam Richardson6ab4b4698451
diff --git a/crates/rope/src/chunk.rs b/crates/rope/src/chunk.rsindex c158d2429ea..5c2b9b87c34 100644--- a/crates/rope/src/chunk.rs+++ b/crates/rope/src/chunk.rs@@ -504,8 +504,6 @@ impl<'a> ChunkSlice<'a> {#[inline(always)]pub fn tabs(&self) -> Tabs {Tabs {- byte_offset: 0,- char_offset: 0,tabs: self.tabs,chars: self.chars,}@@ -513,8 +511,6 @@ impl<'a> ChunkSlice<'a> {}pub struct Tabs {- byte_offset: usize,- char_offset: usize,tabs: u128,chars: u128,}@@ -536,21 +532,14 @@ impl Iterator for Tabs {let tab_offset = self.tabs.trailing_zeros() as usize;let chars_mask = (1 << tab_offset) - 1;let char_offset = (self.chars & chars_mask).count_ones() as usize;- self.byte_offset += tab_offset;- self.char_offset += char_offset;++ // Since tabs are 1 byte the tab offset is the same as the byte offsetlet position = TabPosition {- byte_offset: self.byte_offset,- char_offset: self.char_offset,+ byte_offset: tab_offset,+ char_offset: char_offset,};-- self.byte_offset += 1;- self.char_offset += 1;- if self.byte_offset == MAX_BASE {- self.tabs = 0;- } else {- self.tabs >>= tab_offset + 1;- self.chars >>= tab_offset + 1;- }+ // Remove the tab we've just seen+ self.tabs ^= 1 << tab_offset;Some(position)}