Open achille-roussel opened 4 years ago
Hello @twmb, would you like to get this PR merged or would you prefer not to bring it in?
I'm not a gate on this repo, I just saw the PR and decided to look since I fixed roughly the same thing in my own fork from way back.
We're maintaining a fork as well which includes this optimization https://github.com/segmentio/murmur3 (in case it is useful to someone).
Hello!
This PR adds a
WriteString
method to the internaldigest
type to implement theio.StringWriter
interface and avoid memory copies when hashing strings.I added a benchmark and ran it before and after the change to demonstrate that a heap allocation is removed by providing this method:
The use of the
unsafe
package is a bit unfortunate, but it seemed like the package already depended on it, so this change doesn't introduce a new dependency onunsafe
.Let me know if you'd like to see anything changed!