Skip to content

Commit

Permalink
Use hashbrown's extend_reserve() in HashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
inquisitivecrystal committed Jul 20, 2021
1 parent c9aa259 commit e7fe2df
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2786,15 +2786,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);
}
}

Expand Down

0 comments on commit e7fe2df

Please sign in to comment.