Open sergeyt opened 4 years ago
Perhaps it is minor thing, but it would be nice to have some day
Note that iterating over the chars is going to be pretty slow, and unpaired surrogates will need to be handled somehow, so we can't just rely on Rust's char
. But maybe we can use u32
instead.
The hash code could be calculated in JS, so there'd be only one call to JS instead of one call per char.
@0xd4d That's not how Hash trait works. It's supposed to work with variety of different hashers, so it expects you to write bytes to the provided Hasher and it would do the rest.
Either using charCodeAt
for iterating over u32
s as @Pauan suggested, or encoding string into binary, would be the correct solution. Just needs measurements on which one is actually faster.
Motivation
This allows using
JsString
value as key inHashMap
.Proposed Solution
It should be straitword, just iterate over chars and write them to hasher.
Alternatives
You can use
String::from(value)
to convertJsString
value to String.