mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Auto merge of #120024 - Mark-Simulacrum:fast-union-merge, r=cjgillot
Merge into larger interval set This reduces the work done while merging rows. In at least one case (#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 cuts the runtime of the test case in #50450 from ~26 seconds to ~6 seconds locally, though it doesn't change the memory usage peak (~9.5GB).
This commit is contained in:
commit
6351247048
@ -236,6 +236,12 @@ impl<I: Idx> IntervalSet<I> {
|
||||
I: Step,
|
||||
{
|
||||
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;
|
||||
for range in other.iter_intervals() {
|
||||
did_insert |= self.insert_range(range);
|
||||
|
Loading…
Reference in New Issue
Block a user