You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In many situations, we have a string on hand rather than a []byte and we want to write that string into a hash.Hash.
Converting to []byte to call hash.Hash.Write is unfortunate since it allocates.
I propose that all (or most) implementations of hash.Hash also implement io.StringWriter. This would not require any changes to the hash.Hash interface (which can't change for compatibility reasons), but would allow anyone calling io.WriteString(h, s) to automatically benefit from allocation-free hashing.
The text was updated successfully, but these errors were encountered:
In many situations, we have a
string
on hand rather than a[]byte
and we want to write thatstring
into ahash.Hash
.Converting to
[]byte
to callhash.Hash.Write
is unfortunate since it allocates.I propose that all (or most) implementations of
hash.Hash
also implementio.StringWriter
. This would not require any changes to thehash.Hash
interface (which can't change for compatibility reasons), but would allow anyone callingio.WriteString(h, s)
to automatically benefit from allocation-free hashing.The text was updated successfully, but these errors were encountered: