-
Notifications
You must be signed in to change notification settings - Fork 14k
Description
str and [u8] hash differently and have done since the solution to #5257.
This is inconvenient in that it leads to things like the StrTendril type (from the tendril crate) hashing like a [u8] rather than like a str; one is thus unable to happily implement Borrow<str> on it in order to make HashMap<StrTendril, _> palatable.
[u8] gets its length prepended, while str gets 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 that str should 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.