Add a layer of indirection between excerpt ids and locators

This commit is contained in:
Max Brunsfeld 2022-11-23 16:13:10 -08:00
parent 0b0fe91545
commit f71145bb32
8 changed files with 297 additions and 166 deletions

View file

@ -3,8 +3,8 @@ use smallvec::{smallvec, SmallVec};
use std::iter;
lazy_static! {
pub static ref MIN: Locator = Locator::min();
pub static ref MAX: Locator = Locator::max();
static ref MIN: Locator = Locator::min();
static ref MAX: Locator = Locator::max();
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@ -19,6 +19,14 @@ impl Locator {
Self(smallvec![u64::MAX])
}
pub fn min_ref() -> &'static Self {
&*MIN
}
pub fn max_ref() -> &'static Self {
&*MAX
}
pub fn assign(&mut self, other: &Self) {
self.0.resize(other.0.len(), 0);
self.0.copy_from_slice(&other.0);

View file

@ -1770,9 +1770,9 @@ impl BufferSnapshot {
fn fragment_id_for_anchor(&self, anchor: &Anchor) -> &Locator {
if *anchor == Anchor::MIN {
&locator::MIN
Locator::min_ref()
} else if *anchor == Anchor::MAX {
&locator::MAX
Locator::max_ref()
} else {
let anchor_key = InsertionFragmentKey {
timestamp: anchor.timestamp,