Skip to content

proposal: hash: all implementations of Hash should implement io.StringWriter #54379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dsnet opened this issue Aug 10, 2022 · 1 comment
Closed

Comments

@dsnet
Copy link
Member

dsnet commented Aug 10, 2022

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.

@dsnet dsnet added the Proposal label Aug 10, 2022
@gopherbot gopherbot added this to the Proposal milestone Aug 10, 2022
@dsnet
Copy link
Member Author

dsnet commented Aug 10, 2022

Hah. Already proposed and accepted: #38776

@dsnet dsnet closed this as completed Aug 10, 2022
@golang golang locked and limited conversation to collaborators Aug 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants