From e9c385e7a6706b791e811d0b82e2b49dd0788c97 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 9 Dec 2021 18:27:54 +0100 Subject: [PATCH] WIP --- crates/text/src/locator.rs | 21 +++++++++++++++------ crates/text/src/text.rs | 4 ++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/text/src/locator.rs b/crates/text/src/locator.rs index 0a22ea58f904b4fc28efc2ac785bd67ef5abd2dd..249e79b6fd866a149bc54187651e17235c97b7ad 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 c2e0d8e4ef0b7b4f7bb327ae250620c19732d7fe..398550165953dee820a72b4ce12bd840a3cb77c6 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); } }