Skip to content

Commit 2c66e28

Browse files
committed
Fix the comparison of union set sizes
1 parent 496b1bc commit 2c66e28

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/set.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,9 @@ where
736736
/// ```
737737
#[cfg_attr(feature = "inline-more", inline)]
738738
pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, T, S, A> {
739-
let (smaller, larger) = if self.len() >= other.len() {
739+
// We'll iterate one set in full, and only the remaining difference from the other.
740+
// Use the smaller set for the difference in order to reduce hash lookups.
741+
let (smaller, larger) = if self.len() <= other.len() {
740742
(self, other)
741743
} else {
742744
(other, self)

0 commit comments

Comments
 (0)