Skip to content

cmd/gc: allocate slice for []byte -> string conversion on heap. #9748

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
DanielMorsing opened this issue Feb 1, 2015 · 1 comment
Closed

Comments

@DanielMorsing
Copy link
Contributor

A pattern that I've been finding myself writing a lot recently is

func somefunc() string {
    b := make([]byte, 0, somecap)
    // build a string component by component
    return string(b)
}

In the case where we don't touch the byte slice after the string conversion and the byte slice otherwise doesn't escape, we can allocate the slice on the heap and use the non-copying slicetostringtmp function to create the string, eliminating copying and an allocation.

@dvyukov dvyukov closed this as completed Feb 1, 2015
@dvyukov
Copy link
Member

dvyukov commented Feb 1, 2015

Dup of #6714

@golang golang locked and limited conversation to collaborators Jun 25, 2016
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

3 participants