Let's say I have a massive String, so hashing it is fairly expensive.
When does the hashValue gets computed? Every time I access it as words.hashValue
, or every time the String gets modified? If it's on access, is it cached?
Let's say I have a massive String, so hashing it is fairly expensive.
When does the hashValue gets computed? Every time I access it as words.hashValue
, or every time the String gets modified? If it's on access, is it cached?
As the docs on
hashValue
state, that requirement onHashable
is deprecated, you should be usinghash(into:)
instead, which should only be called when you are storing theString
as aHashable
, by using it as aDictionary
key or in aSet
.For more info, see SE-0206 Hashable enhancements.