Optimize anchor comparison and take full advantage of fragment IDs

This commit is contained in:
Antonio Scandurra 2021-12-10 09:16:58 +01:00
parent 1ed1ec21dd
commit eeba0993aa
5 changed files with 19 additions and 13 deletions

View file

@ -28,15 +28,17 @@ impl Anchor {
}
pub fn cmp<'a>(&self, other: &Anchor, buffer: &Snapshot) -> Result<Ordering> {
let offset_comparison = if self.timestamp == other.timestamp {
self.offset.cmp(&other.offset)
let fragment_id_comparison = if self.timestamp == other.timestamp {
Ordering::Equal
} else {
buffer
.full_offset_for_anchor(self)
.cmp(&buffer.full_offset_for_anchor(other))
.fragment_id_for_anchor(self)
.cmp(&buffer.fragment_id_for_anchor(other))
};
Ok(offset_comparison.then_with(|| self.bias.cmp(&other.bias)))
Ok(fragment_id_comparison
.then_with(|| self.offset.cmp(&other.offset))
.then_with(|| self.bias.cmp(&other.bias)))
}
pub fn bias_left(&self, buffer: &Buffer) -> Anchor {