diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2019-11-12 16:36:15 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-12 16:36:15 +0900 |
| commit | 6bdd1beca6d310f0baaffa0835a16a968061ccfb (patch) | |
| tree | 01acb6acf43db5c6b1c84b7713518a1e924f3b7b | |
| parent | 8e0265c268c06a23f9107a1b28ca1dedf7c59fe7 (diff) | |
| parent | 04a237b9e2c327e1ad6339afd2f967bfcad38483 (diff) | |
| download | rust-6bdd1beca6d310f0baaffa0835a16a968061ccfb.tar.gz rust-6bdd1beca6d310f0baaffa0835a16a968061ccfb.zip | |
Rollup merge of #66280 - stepancheg:union, r=alexcrichton
Fix HashSet::union performance Consider this example: small_set = 0..2, large_set = 0..1000. To efficiently compute the union of these sets, we should * take all elements of the larger set * for each element of the smaller set check it is not in the larger set This is exactly what this commit does. This particular optimization was implemented a year ago, but the author mistaken `<` and `>`.
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 092fb443468..a038ee80210 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -551,7 +551,7 @@ impl<T, S> HashSet<T, S> #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> { - if self.len() <= other.len() { + if self.len() >= other.len() { Union { iter: self.iter().chain(other.difference(self)), } |
