Optimize anchor comparison and take full advantage of fragment IDs
This commit is contained in:
parent
1ed1ec21dd
commit
eeba0993aa
5 changed files with 19 additions and 13 deletions
|
@ -1763,12 +1763,11 @@ impl Snapshot {
|
|||
}
|
||||
}
|
||||
|
||||
fn full_offset_for_anchor(&self, anchor: &Anchor) -> FullOffset {
|
||||
fn fragment_id_for_anchor(&self, anchor: &Anchor) -> &Locator {
|
||||
if *anchor == Anchor::min() {
|
||||
Default::default()
|
||||
&locator::MIN
|
||||
} else if *anchor == Anchor::max() {
|
||||
let text = self.fragments.summary().text;
|
||||
FullOffset(text.visible + text.deleted)
|
||||
&locator::MAX
|
||||
} else {
|
||||
let anchor_key = InsertionFragmentKey {
|
||||
timestamp: anchor.timestamp,
|
||||
|
@ -1790,10 +1789,7 @@ impl Snapshot {
|
|||
}
|
||||
let insertion = insertion_cursor.item().expect("invalid insertion");
|
||||
debug_assert_eq!(insertion.timestamp, anchor.timestamp, "invalid insertion");
|
||||
|
||||
let mut fragment_cursor = self.fragments.cursor::<(Option<&Locator>, FullOffset)>();
|
||||
fragment_cursor.seek(&Some(&insertion.fragment_id), Bias::Left, &None);
|
||||
fragment_cursor.start().1 + (anchor.offset - insertion.split_offset)
|
||||
&insertion.fragment_id
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue