Skip to content

Commit 6bdd1be

Browse files
authored
Rollup merge of #66280 - stepancheg:union, r=alexcrichton
Fix HashSet::union performance Consider this example: small_set = 0..2, large_set = 0..1000. To efficiently compute the union of these sets, we should * take all elements of the larger set * for each element of the smaller set check it is not in the larger set This is exactly what this commit does. This particular optimization was implemented a year ago, but the author mistaken `<` and `>`.
2 parents 8e0265c + 04a237b commit 6bdd1be

File tree

1 file changed

+1
-1
lines changed
  • src/libstd/collections/hash

1 file changed

+1
-1
lines changed

src/libstd/collections/hash/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl<T, S> HashSet<T, S>
551551
#[inline]
552552
#[stable(feature = "rust1", since = "1.0.0")]
553553
pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> {
554-
if self.len() <= other.len() {
554+
if self.len() >= other.len() {
555555
Union {
556556
iter: self.iter().chain(other.difference(self)),
557557
}

0 commit comments

Comments
 (0)