-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Do some cleanups for hashmaps #45263
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
Conversation
@arthurprs is probably interested in this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
src/libstd/collections/hash/table.rs
Outdated
@@ -768,7 +767,7 @@ impl<K, V> RawTable<K, V> { | |||
// This is great in theory, but in practice getting the alignment | |||
// right is a little subtle. Therefore, calculating offsets has been | |||
// factored out into a different function. | |||
let (alignment, hash_offset, size, oflo) = calculate_allocation(hashes_size, | |||
let (alignment, size, oflo) = calculate_allocation(hashes_size, | |||
align_of::<HashUint>(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: lines bellow need some formating adjustments.
@@ -1157,6 +1156,7 @@ impl<K: Clone, V: Clone> Clone for RawTable<K, V> { | |||
} | |||
|
|||
new_ht.size = self.size(); | |||
new_ht.set_tag(self.tag()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I overlooked that before.
fb187f8
to
85bc99e
Compare
Fixed |
85bc99e
to
9d70129
Compare
This offset is always zero, and we don't consistently take it into account. This is okay, because it's zero, but if it ever changes we're going to have bugs (e.g. in the `dealloc` call, where we don't take it into account). It's better to remove this for now; if we ever have a need for a nonzero offset we can add it back, and handle it properly when we do so.
This isn't strictly necessary for hashmap cloning to work. The tag is used to hint for an upcoming resize, so it's good to copy this information over. (We can do cleverer things like actually resizing the hashmap when we see the tag, or even cleaning up the entry order, but this requires more thought and might not be worth it)
9d70129
to
e8e7715
Compare
@bors r+ rollup Thanks @Manishearth and @arthurprs |
📌 Commit e8e7715 has been approved by |
Do some cleanups for hashmaps @mystor noticed some things whilst reading through the hashmap RawTable code. Firstly, in RawTable we deal with this hash_offset value that is the offset of the list of hashes from the buffer start. This is always zero, and this isn't consistently used (which means that we would have bugs if we set it to something else). We should just remove this since it doesn't help us at all. Secondly, the probing length tag is not copied when cloning a raw table. This is minor and basically means we do a bit more work than we need on further inserts on a cloned hashmap. r? @gankro
Do some cleanups for hashmaps @mystor noticed some things whilst reading through the hashmap RawTable code. Firstly, in RawTable we deal with this hash_offset value that is the offset of the list of hashes from the buffer start. This is always zero, and this isn't consistently used (which means that we would have bugs if we set it to something else). We should just remove this since it doesn't help us at all. Secondly, the probing length tag is not copied when cloning a raw table. This is minor and basically means we do a bit more work than we need on further inserts on a cloned hashmap. r? @gankro
@mystor noticed some things whilst reading through the hashmap RawTable code.
Firstly, in RawTable we deal with this hash_offset value that is the offset of the list of hashes from the buffer start. This is always zero, and this isn't consistently used (which means that we would have bugs if we set it to something else). We should just remove this since it doesn't help us at all.
Secondly, the probing length tag is not copied when cloning a raw table. This is minor and basically means we do a bit more work than we need on further inserts on a cloned hashmap.
r? @gankro