Skip to content

Commit 5b8bfe0

Browse files
committed
improve worst-case performance of HashSet.is_subset
1 parent 546cb21 commit 5b8bfe0

File tree

1 file changed

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

1 file changed

+5
-1
lines changed

src/libstd/collections/hash/set.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,11 @@ impl<T, S> HashSet<T, S>
627627
/// ```
628628
#[stable(feature = "rust1", since = "1.0.0")]
629629
pub fn is_subset(&self, other: &HashSet<T, S>) -> bool {
630-
self.iter().all(|v| other.contains(v))
630+
if self.len() <= other.len() {
631+
self.iter().all(|v| other.contains(v))
632+
} else {
633+
false
634+
}
631635
}
632636

633637
/// Returns `true` if the set is a superset of another,

0 commit comments

Comments
 (0)