Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid iteration when dropping HashMaps whose items don't need dropping #31718

Merged
merged 1 commit into from
Feb 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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