Merge into larger interval set
This reduces the work done while merging rows. In at least one case (issue 50450), we have thousands of union([range], [20,000 ranges]), which previously inserted each of the 20,000 ranges one by one. Now we only insert one range into the right hand set after copying the set over.
This commit is contained in:
parent
665d2c6f2c
commit
1696148a89
@ -236,6 +236,12 @@ pub fn union(&mut self, other: &IntervalSet<I>) -> bool
|
|||||||
I: Step,
|
I: Step,
|
||||||
{
|
{
|
||||||
assert_eq!(self.domain, other.domain);
|
assert_eq!(self.domain, other.domain);
|
||||||
|
if self.map.len() < other.map.len() {
|
||||||
|
let backup = self.clone();
|
||||||
|
self.map.clone_from(&other.map);
|
||||||
|
return self.union(&backup);
|
||||||
|
}
|
||||||
|
|
||||||
let mut did_insert = false;
|
let mut did_insert = false;
|
||||||
for range in other.iter_intervals() {
|
for range in other.iter_intervals() {
|
||||||
did_insert |= self.insert_range(range);
|
did_insert |= self.insert_range(range);
|
||||||
|
Loading…
Reference in New Issue
Block a user