From 84fe7f50ac3bbb2ccf6e7e800fe829de06bab266 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 2 Jun 2021 12:24:00 +0200 Subject: [PATCH] Speed up anchor comparison when the version is the same --- zed/src/editor/buffer/anchor.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/zed/src/editor/buffer/anchor.rs b/zed/src/editor/buffer/anchor.rs index 1f44eb65f0fc81d17f6a5e08614660a768ffa269..145330416c183d1141871fe916f7388b5ad4f1fb 100644 --- a/zed/src/editor/buffer/anchor.rs +++ b/zed/src/editor/buffer/anchor.rs @@ -61,15 +61,26 @@ impl Anchor { (Anchor::End, _) | (_, Anchor::Start) => Ordering::Greater, ( Anchor::Middle { - bias: self_bias, .. + offset: self_offset, + bias: self_bias, + version: self_version, }, Anchor::Middle { - bias: other_bias, .. + offset: other_offset, + bias: other_bias, + version: other_version, }, - ) => buffer - .full_offset_for_anchor(self) - .cmp(&buffer.full_offset_for_anchor(other)) - .then_with(|| self_bias.cmp(&other_bias)), + ) => { + let offset_comparison = if self_version == other_version { + self_offset.cmp(other_offset) + } else { + buffer + .full_offset_for_anchor(self) + .cmp(&buffer.full_offset_for_anchor(other)) + }; + + offset_comparison.then_with(|| self_bias.cmp(&other_bias)) + } }) }