diff options
| author | Stein Somers <git@steinsomers.be> | 2019-04-03 13:01:01 +0200 |
|---|---|---|
| committer | Stein Somers <git@steinsomers.be> | 2019-04-03 13:01:01 +0200 |
| commit | 5b8bfe047123bad63ead0370c165cd9307a07caa (patch) | |
| tree | 212121e7414ce359f94211d04c684262b173c9c6 /src/libstd | |
| parent | 546cb21f580ae3d4e0bf42ccecfad4a34defebe7 (diff) | |
| download | rust-5b8bfe047123bad63ead0370c165cd9307a07caa.tar.gz rust-5b8bfe047123bad63ead0370c165cd9307a07caa.zip | |
improve worst-case performance of HashSet.is_subset
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 89d5b2ff30f..b9fcc2365fa 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -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, |
