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:
Yuki Okushi 2021-07-28 18:28:14 +09:00 committed by GitHub
commit 98f7a009fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
}