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:
Martin von Zweigbergk 2022-03-09 10:42:39 -08:00 committed by Martin von Zweigbergk
parent b64ee147ae
commit 934564bf8d

View file

@ -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))
}
}