Skip to content

Commit 7e2da14

Browse files
bors[bot]Amanieu
andcommitted
Merge #67
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]>
2 parents ddf59a9 + 8ec72d0 commit 7e2da14

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/map.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ where
626626
/// down no lower than the supplied limit while maintaining the internal rules
627627
/// and possibly leaving some space in accordance with the resize policy.
628628
///
629-
/// Panics if the current capacity is smaller than the supplied
630-
/// minimum capacity.
629+
/// This function does nothing if the current capacity is smaller than the
630+
/// supplied minimum capacity.
631631
///
632632
/// # Examples
633633
///
@@ -642,14 +642,11 @@ where
642642
/// assert!(map.capacity() >= 10);
643643
/// map.shrink_to(0);
644644
/// assert!(map.capacity() >= 2);
645+
/// map.shrink_to(10);
646+
/// assert!(map.capacity() >= 2);
645647
/// ```
646648
#[inline]
647649
pub fn shrink_to(&mut self, min_capacity: usize) {
648-
assert!(
649-
self.capacity() >= min_capacity,
650-
"Tried to shrink to a larger capacity"
651-
);
652-
653650
let hash_builder = &self.hash_builder;
654651
self.table
655652
.shrink_to(min_capacity, |x| make_hash(hash_builder, &x.0));

src/raw/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,7 @@ impl<T> RawTable<T> {
601601
};
602602

603603
// If we have more buckets than we need, shrink the table.
604-
if min_buckets != self.buckets() {
605-
debug_assert!(min_buckets < self.buckets());
606-
604+
if min_buckets < self.buckets() {
607605
// Fast path if the table is empty
608606
if self.items == 0 {
609607
*self = Self::with_capacity(min_size)

0 commit comments

Comments
 (0)