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

runtime: zero unused portion of temp buffer in stringtoslice{byte,rune} #14235

Closed
randall77 opened this issue Feb 5, 2016 · 2 comments
Closed

Comments

@randall77
Copy link
Contributor

Maybe we should zero the unused portion of the temp buffer instead of reducing the capacity of the returned slice.

See issue #14232

@randall77 randall77 added this to the Go1.7 milestone Feb 5, 2016
@ianlancetaylor ianlancetaylor changed the title Zero unused portion of temp buffer in stringtoslice{byte,rune} runtime: zero unused portion of temp buffer in stringtoslice{byte,rune} Feb 5, 2016
@randall77
Copy link
Contributor Author

Zeroing the tmpBuf is only 4 instructions (on amd64), so it is probably worth it. It allows things like the append in the following function to work without allocation:

func g(s, t string) string {
    b := ([]byte)(s)
    b = append(b, ([]byte)(t)...)
    return string(b)
}

@randall77 randall77 self-assigned this Apr 25, 2016
@gopherbot
Copy link

CL https://golang.org/cl/22424 mentions this issue.

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