Skip to content

Commit

Permalink
Merge rust-lang#67
Browse files Browse the repository at this point in the history
67: Change shrink_to to not panic if min_capacity < capacity r=Amanieu a=Amanieu

cc rust-lang/rust#56431

Co-authored-by: Amanieu d'Antras <[email protected]>
  • Loading branch information
bors[bot] and Amanieu committed Apr 22, 2019
2 parents ddf59a9 + 8ec72d0 commit 7e2da14
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ where
/// down no lower than the supplied limit while maintaining the internal rules
/// and possibly leaving some space in accordance with the resize policy.
///
/// Panics if the current capacity is smaller than the supplied
/// minimum capacity.
/// This function does nothing if the current capacity is smaller than the
/// supplied minimum capacity.
///
/// # Examples
///
Expand All @@ -642,14 +642,11 @@ where
/// assert!(map.capacity() >= 10);
/// map.shrink_to(0);
/// assert!(map.capacity() >= 2);
/// map.shrink_to(10);
/// assert!(map.capacity() >= 2);
/// ```
#[inline]
pub fn shrink_to(&mut self, min_capacity: usize) {
assert!(
self.capacity() >= min_capacity,
"Tried to shrink to a larger capacity"
);

let hash_builder = &self.hash_builder;
self.table
.shrink_to(min_capacity, |x| make_hash(hash_builder, &x.0));
Expand Down
4 changes: 1 addition & 3 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,7 @@ impl<T> RawTable<T> {
};

// If we have more buckets than we need, shrink the table.
if min_buckets != self.buckets() {
debug_assert!(min_buckets < self.buckets());

if min_buckets < self.buckets() {
// Fast path if the table is empty
if self.items == 0 {
*self = Self::with_capacity(min_size)
Expand Down

0 comments on commit 7e2da14

Please sign in to comment.