Skip to content
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: allow the first arguments of append function calls to be strings if they are supposed to be byte slices #43429

Open
go101 opened this issue Dec 30, 2020 · 0 comments
Labels
Projects
Milestone

Comments

@go101
Copy link

@go101 go101 commented Dec 30, 2020

Search append([]byte( in the Go project, there are at least 8 append calls
with 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
to avoid the unnecessary allocations,
(in fact, not made yet) but the proposal makes
Go 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 first
argument 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.

@gopherbot gopherbot added this to the Proposal milestone Dec 30, 2020
@go101 go101 changed the title Proposal: allow the first arguments of append function calls to be strings Proposal: allow the first arguments of append function calls to be strings if they are sopposued to be byte slices Dec 30, 2020
@go101 go101 changed the title Proposal: allow the first arguments of append function calls to be strings if they are sopposued to be byte slices Proposal: allow the first arguments of append function calls to be strings if they are supposed to be byte slices Dec 30, 2020
@ianlancetaylor ianlancetaylor changed the title Proposal: allow the first arguments of append function calls to be strings if they are supposed to be byte slices proposal: allow the first arguments of append function calls to be strings if they are supposed to be byte slices Dec 30, 2020
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Proposals
Incoming
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants