-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Open
Labels
Milestone
Description
Currently the strings.Builder wastes the remaining capacity when (*Builder).Reset is being called, it works just the same way as creating a new empty strings.Builder.
// Reset resets the Builder to be empty.
func (b *Builder) Reset() {
b.addr = nil
b.buf = nil
}Currently it is not possible in a backwards compatibility manner to keep the remaining capacity in the Builder after calling Reset(), because it would require keeping the b.addr pointer, so that it is not possible to copy the Builder.
I propose adding a simple (*Builder).ResetKeepCapacity method with following signature:
// ResetKeepCapacity resets the builder and keeps the remaining
// capacity (b.Cap() - b.Len()) for future use.
func (b *Builder) ResetKeepCapacity() {
b.buf = b.buf[len(b.buf):]
}tjpalmer
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Incoming