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: implement NewBuilder for strings.Builder in go 1.10 #22776

Closed
dongweigogo opened this issue Nov 17, 2017 · 2 comments
Closed

proposal: implement NewBuilder for strings.Builder in go 1.10 #22776

dongweigogo opened this issue Nov 17, 2017 · 2 comments

Comments

@dongweigogo
Copy link

dongweigogo commented Nov 17, 2017

currently go 1.9.2

From the Go 1.10 Release Notes, a convenient string Builder is added in strings package.
A NewBuilder function can be implemented to initialize the internal buffer with a specified capacity. As below:

func NewBuilder(n int) *Builder {
    
    b:=&Builder{buf: make([]byte, 0, n)}
    
    return b

}
@gopherbot gopherbot added this to the Proposal milestone Nov 17, 2017
@nussjustin
Copy link
Contributor

There was going to be a NewBuilderSize function, but it was removed since you can already do the same thing using Grow:

var b strings.Builder
b.Grow(n)

See Brads comment on the CL

@ALTree ALTree changed the title Proposal: implement NewBuilder for strings.Builder in go 1.10 proposal: implement NewBuilder for strings.Builder in go 1.10 Nov 17, 2017
@bradfitz
Copy link
Contributor

Yeah, closing. I'd prefer less API here. It's already kinda weird.

@golang golang locked and limited conversation to collaborators Nov 17, 2018
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

4 participants