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.
This commit is contained in:
commit
98f7a009fa
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user