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 on Hashable
is deprecated, you should be using hash(into:)
instead, which should only be called when you are storing the String
as a Hashable
, by using it as a Dictionary
key or in a Set
.
For more info, see SE-0206 Hashable enhancements.