Skip to content

Commit 98f7a00

Browse files
authored
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.
2 parents 911e22b + e7fe2df commit 98f7a00

File tree

1 file changed

+1
-9
lines changed
  • library/std/src/collections/hash

1 file changed

+1
-9
lines changed

library/std/src/collections/hash/map.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -2821,15 +2821,7 @@ where
28212821

28222822
#[inline]
28232823
fn extend_reserve(&mut self, additional: usize) {
2824-
// self.base.extend_reserve(additional);
2825-
// FIXME: hashbrown should implement this method.
2826-
// But until then, use the same reservation logic:
2827-
2828-
// Reserve the entire hint lower bound if the map is empty.
2829-
// Otherwise reserve half the hint (rounded up), so the map
2830-
// will only resize twice in the worst case.
2831-
let reserve = if self.is_empty() { additional } else { (additional + 1) / 2 };
2832-
self.base.reserve(reserve);
2824+
self.base.extend_reserve(additional);
28332825
}
28342826
}
28352827

0 commit comments

Comments
 (0)