about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-07-28 18:28:14 +0900
committerGitHub <noreply@github.com>2021-07-28 18:28:14 +0900
commit98f7a009faad2012bacd5119c582fdbd52712174 (patch)
tree7af61a30a954a2447f71f07aeb95da9984c23e43
parent911e22b57d05e7514accb55d25ad2083aae54201 (diff)
parente7fe2dfef253c462699783e7b2b297827f7440a7 (diff)
downloadrust-98f7a009faad2012bacd5119c582fdbd52712174.tar.gz
rust-98f7a009faad2012bacd5119c582fdbd52712174.zip
Rollup merge of #87330 - inquisitivecrystal:extend-reserve, r=JohnTitor
Use hashbrown's `extend_reserve()` in `HashMap`

When we added `extend_reserve()` to our implementation of `Extend` for `HashMap`, hashbrown didn't have a version we could use. Now that hashbrown has added it, we should use its version instead of implementing it ourself.
-rw-r--r--library/std/src/collections/hash/map.rs10
1 files changed, 1 insertions, 9 deletions
diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs
index b102fd9d5bf..933d686521e 100644
--- a/library/std/src/collections/hash/map.rs
+++ b/library/std/src/collections/hash/map.rs
@@ -2821,15 +2821,7 @@ where
 
     #[inline]
     fn extend_reserve(&mut self, additional: usize) {
-        // self.base.extend_reserve(additional);
-        // FIXME: hashbrown should implement this method.
-        // But until then, use the same reservation logic:
-
-        // Reserve the entire hint lower bound if the map is empty.
-        // Otherwise reserve half the hint (rounded up), so the map
-        // will only resize twice in the worst case.
-        let reserve = if self.is_empty() { additional } else { (additional + 1) / 2 };
-        self.base.reserve(reserve);
+        self.base.extend_reserve(additional);
     }
 }