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
proposal: spec: allow append(string, ...) and view the string argument as a byte slice #43429
Comments
This proposal does not make Go more consistent, as claimed. It would be completely fine for the compiler to optimize away the allocation in |
I mean it makes |
This proposal has been added to the active column of the proposals project |
Based on the discussion above, this proposal seems like a likely decline. |
OK. But it looks there are no effective discussions here. |
No change in consensus, so declined. |
Search
append([]byte(
in the Go project, there are at least 8 append callswith the first arguments as conversions from string to []byte.
If the first argument of such an append call is allowed to be a string,
then an unnecessary allocation may be avoided.
Although it looks the official Go compiler has made an optimization here(in fact, not made yet)to avoid the unnecessary allocations,
butthe proposal makesGo code more consistent (with the second arguments, which can be strings already)
and look cleaner.
Besides these aforementioned benefits (cleaner, more consistent and efficient),
this change could also partically remedy the fact of lack of a simple way to
decap the first arguments of append calls (for the scenarios they are []byte).
We can use a
string(aByteSlice)
conversion as the firstargument of an append call to hint that the first argument is decaped.
It is easy for compilers to not make an allocation for such conversions.
The text was updated successfully, but these errors were encountered: