Skip to content

Commit af990b6

Browse files
committed
Implement the length optimization for par_union
1 parent 2c66e28 commit af990b6

File tree

1 file changed

+9
-2
lines changed
  • src/external_trait_impls/rayon

1 file changed

+9
-2
lines changed

src/external_trait_impls/rayon/set.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,16 @@ where
198198
where
199199
C: UnindexedConsumer<Self::Item>,
200200
{
201-
self.a
201+
// We'll iterate one set in full, and only the remaining difference from the other.
202+
// Use the smaller set for the difference in order to reduce hash lookups.
203+
let (smaller, larger) = if self.a.len() <= self.b.len() {
204+
(self.a, self.b)
205+
} else {
206+
(self.b, self.a)
207+
};
208+
larger
202209
.into_par_iter()
203-
.chain(self.b.par_difference(self.a))
210+
.chain(smaller.par_difference(larger))
204211
.drive_unindexed(consumer)
205212
}
206213
}

0 commit comments

Comments
 (0)