Skip to content

Commit 2051a92

Browse files
committed
Auto merge of #31718 - apasel422:issue-31711, r=bluss
This changes the performance of `drop` from linear to constant time for such `HashMap`s. Closes #31711. r? @bluss
2 parents b54770c + f890772 commit 2051a92

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/libstd/collections/hash/table.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use alloc::heap::{allocate, deallocate, EMPTY};
1212

1313
use cmp;
1414
use hash::{Hash, Hasher, BuildHasher};
15+
use intrinsics::needs_drop;
1516
use marker;
1617
use mem::{align_of, size_of};
1718
use mem;
@@ -1009,7 +1010,9 @@ impl<K, V> Drop for RawTable<K, V> {
10091010
// dropping empty tables such as on resize.
10101011
// Also avoid double drop of elements that have been already moved out.
10111012
unsafe {
1012-
for _ in self.rev_move_buckets() {}
1013+
if needs_drop::<(K, V)>() { // avoid linear runtime for types that don't need drop
1014+
for _ in self.rev_move_buckets() {}
1015+
}
10131016
}
10141017

10151018
let hashes_size = self.capacity * size_of::<u64>();

0 commit comments

Comments
 (0)