Stop hashing a usize when hashing [u8; 1]#86131
Closed
scottmcm wants to merge 1 commit into
Closed
Conversation
Contributor
|
(rust-highfive has picked a reviewer for you, use r? to override) |
petrochenkov
reviewed
Jun 8, 2021
| /// | ||
| /// For example, the hash of the array `[x, y, z]` may or may not be the same as | ||
| /// the hash of the tuple `(x, y, z)`, and the hash of the array `[x, y, z]` may | ||
| /// or may not be the same as the hash of the vector `vec![x, y, z]`. |
Contributor
There was a problem hiding this comment.
This may be in conflict with requirements of the Borrow trait which is implemented for arrays and slices.
Contributor
There was a problem hiding this comment.
Here's a playground. Shows the problem and a workaround.
Member
Author
|
🤦 Thanks, @petrochenkov. I'd checked That's definitely fatal to this change. I'll make a new PR so there's actually a test failure if the implementation is changed. Edit: New PR up at #86140 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This changes
Hashfor arrays to be implemented viaHash::hash_sliceinstead of via<[T]>::hash. The latter calls the former, but only after also hashing the length, which is unnecessary overhead for arrays where it's always the same.I was inspired to make this PR because I changed an old project from having a
HashMap<(usize, usize), _>to having aHashMap<[usize; 2], _>, and was surprised to see the perf worsen from 3.62s to 4.30s.(Yes, that project really is dominated by hash table lookups that badly.)