diff --git a/crates/text/src/locator.rs b/crates/text/src/locator.rs index 0a22ea58f9..249e79b6fd 100644 --- a/crates/text/src/locator.rs +++ b/crates/text/src/locator.rs @@ -2,23 +2,28 @@ use smallvec::{smallvec, SmallVec}; use std::iter; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct Locator(SmallVec<[u8; 4]>); +pub struct Locator(SmallVec<[u64; 4]>); impl Locator { pub fn min() -> Self { - Self(smallvec![u8::MIN]) + Self(smallvec![u64::MIN]) } pub fn max() -> Self { - Self(smallvec![u8::MAX]) + Self(smallvec![u64::MAX]) + } + + pub fn assign(&mut self, other: &Self) { + self.0.resize(other.0.len(), 0); + self.0.copy_from_slice(&other.0); } pub fn between(lhs: &Self, rhs: &Self) -> Self { - let lhs = lhs.0.iter().copied().chain(iter::repeat(u8::MIN)); - let rhs = rhs.0.iter().copied().chain(iter::repeat(u8::MAX)); + let lhs = lhs.0.iter().copied().chain(iter::repeat(u64::MIN)); + let rhs = rhs.0.iter().copied().chain(iter::repeat(u64::MAX)); let mut location = SmallVec::new(); for (lhs, rhs) in lhs.zip(rhs) { - let mid = lhs + (rhs.saturating_sub(lhs)) / 2; + let mid = lhs + ((rhs.saturating_sub(lhs)) >> 48); location.push(mid); if mid > lhs { break; @@ -26,6 +31,10 @@ impl Locator { } Self(location) } + + pub fn len(&self) -> usize { + self.0.len() + } } impl Default for Locator { diff --git a/crates/text/src/text.rs b/crates/text/src/text.rs index c2e0d8e4ef..3985501659 100644 --- a/crates/text/src/text.rs +++ b/crates/text/src/text.rs @@ -2002,7 +2002,7 @@ impl sum_tree::Summary for FragmentSummary { type Context = Option; fn add_summary(&mut self, other: &Self, _: &Self::Context) { - self.max_id = other.max_id.clone(); + self.max_id.assign(&other.max_id); self.text.visible += &other.text.visible; self.text.deleted += &other.text.deleted; self.max_version.join(&other.max_version); @@ -2113,7 +2113,7 @@ impl<'a> sum_tree::Dimension<'a, FragmentSummary> for FullOffset { impl<'a> sum_tree::Dimension<'a, FragmentSummary> for Locator { fn add_summary(&mut self, summary: &FragmentSummary, _: &Option) { - *self = summary.max_id.clone(); + self.assign(&summary.max_id); } }