mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 15:16:35 +00:00
diff: also sort base ranges by end point
I wanted to replace the BTreeMap by a Vec and noticed that we actually sometimes end up having a `0..n` range followed by a `0..0` after refinement. We currently compare those two as equal because I had not thought that we could end up attempting to add two ranges with the same start point. When trying to insert the second range (`0..0`), the BTreeMap will keep the existing key (`0..n`) and replace the value. That's probably works, but it's clearly not what I intended. Let's fix by sorting by the end point if the start point is equal. This actually improves some benchmarks by a few percent (maybe because the subsequent compaction can then remove the `0..0` range).
This commit is contained in:
parent
b64ee147ae
commit
934564bf8d
1 changed files with 2 additions and 2 deletions
|
@ -297,13 +297,13 @@ struct BaseRange(Range<usize>);
|
|||
|
||||
impl PartialOrd for BaseRange {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
self.0.start.partial_cmp(&other.0.start)
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for BaseRange {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.0.start.cmp(&other.0.start)
|
||||
self.0.start.cmp(&other.0.start).then_with(|| self.0.end.cmp(&other.0.end))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue