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

cmd/compile: optimize append([]byte(string), ...) to avoid a duplication #47454

Open
go101 opened this issue Jul 29, 2021 · 0 comments
Open

cmd/compile: optimize append([]byte(string), ...) to avoid a duplication #47454

go101 opened this issue Jul 29, 2021 · 0 comments

Comments

@go101
Copy link

@go101 go101 commented Jul 29, 2021

What version of Go are you using (go version)?

$ go version
go version go1.17rc1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

import "testing"

var str = "1234567890123456789012345678901234567890"

func f() {
	_ = append([]byte(str), str...)
}

func main() {
	stat := func( f func() ) int {
		allocs := testing.AllocsPerRun(1, f)
		return int(allocs)
	}
	println(stat(f)) // 2
}

What did you expect to see?

One allocation.

What did you see instead?

Two instead.

The allocation for []byte(str) could be saved.

Partially related to #43429.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants