Skip to content

Commit

Permalink
Auto merge of #31718 - apasel422:issue-31711, r=bluss
Browse files Browse the repository at this point in the history
This changes the performance of `drop` from linear to constant time for such `HashMap`s.

Closes #31711.

r? @bluss
  • Loading branch information
bors committed Feb 17, 2016
2 parents b54770c + f890772 commit 2051a92
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/libstd/collections/hash/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use alloc::heap::{allocate, deallocate, EMPTY};

use cmp;
use hash::{Hash, Hasher, BuildHasher};
use intrinsics::needs_drop;
use marker;
use mem::{align_of, size_of};
use mem;
Expand Down Expand Up @@ -1009,7 +1010,9 @@ impl<K, V> Drop for RawTable<K, V> {
// dropping empty tables such as on resize.
// Also avoid double drop of elements that have been already moved out.
unsafe {
for _ in self.rev_move_buckets() {}
if needs_drop::<(K, V)>() { // avoid linear runtime for types that don't need drop
for _ in self.rev_move_buckets() {}
}
}

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

0 comments on commit 2051a92

Please sign in to comment.