-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
str and [u8] should hash the same #27108
Copy link
Copy link
Open
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
strand[u8]hash differently and have done since the solution to #5257.This is inconvenient in that it leads to things like the
StrTendriltype (from thetendrilcrate) hashing like a[u8]rather than like astr; one is thus unable to happily implementBorrow<str>on it in order to makeHashMap<StrTendril, _>palatable.[u8]gets its length prepended, whilestrgets 0xff appended. Sure, one u8 rather than one usize is theoretically cheaper to hash; but marginally so only, marginally so. I see no good reason why they should use different techniques, and so I suggest thatstrshould be changed to use the hashing technique of[u8]. This will prevent potential nasty surprises and bring us back closer to the blissful land of “str is just [u8] with a UTF-8 guarantee”.Hashes being internal matters, I do not believe this should be considered a breaking change, but it would still probably be a release-notes-worthy change as it could conceivably break eldritch codes.