improve worst-case performance of HashSet.is_subset
This commit is contained in:
parent
546cb21f58
commit
5b8bfe0471
1 changed files with 5 additions and 1 deletions
|
@ -627,7 +627,11 @@ impl<T, S> HashSet<T, S>
|
|||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn is_subset(&self, other: &HashSet<T, S>) -> bool {
|
||||
self.iter().all(|v| other.contains(v))
|
||||
if self.len() <= other.len() {
|
||||
self.iter().all(|v| other.contains(v))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the set is a superset of another,
|
||||
|
|
Loading…
Reference in a new issue