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.
In many situations, we have a
stringon hand rather than a[]byteand we want to write thatstringinto ahash.Hash.Converting to
[]byteto callhash.Hash.Writeis unfortunate since it allocates.I propose that all (or most) implementations of
hash.Hashalso implementio.StringWriter. This would not require any changes to thehash.Hashinterface (which can't change for compatibility reasons), but would allow anyone callingio.WriteString(h, s)to automatically benefit from allocation-free hashing.