Skip to content

Commit

Permalink
Merge into larger interval set
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mark-Simulacrum committed Jan 16, 2024
1 parent 665d2c6 commit 1696148
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_index/src/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1696148

Please sign in to comment.