about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorStein Somers <git@steinsomers.be>2019-01-09 22:19:54 +0100
committerStein Somers <git@steinsomers.be>2019-01-09 22:19:54 +0100
commit8823bf0b403b0ebf348e1f3fa59d74f2843f0c8b (patch)
treeef3438a54e2f0253380af560d465cf650fd61cee /src/libstd
parentccba43df81d5bda37c9e4d231ad4443e6f3a7e44 (diff)
downloadrust-8823bf0b403b0ebf348e1f3fa59d74f2843f0c8b.tar.gz
rust-8823bf0b403b0ebf348e1f3fa59d74f2843f0c8b.zip
Fix poor worst case performance of is_disjoint
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/collections/hash/set.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs
index 627846411bc..c55dd049ec6 100644
--- a/src/libstd/collections/hash/set.rs
+++ b/src/libstd/collections/hash/set.rs
@@ -599,7 +599,11 @@ impl<T, S> HashSet<T, S>
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn is_disjoint(&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 {
+            other.iter().all(|v| !self.contains(v))
+        }
     }
 
     /// Returns `true` if the set is a subset of another,
@@ -1510,7 +1514,6 @@ mod test_set {
         let mut a = HashSet::new();
         let mut b = HashSet::new();
         assert!(a.intersection(&b).next().is_none());
-        assert!(b.intersection(&a).next().is_none());
 
         assert!(a.insert(11));
         assert!(a.insert(1));