mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
strings: add Builder.Cap
To report the capacity of the underlying buffer. The method mirrors bytes.Buffer.Cap. The method can be useful to know whether or not calling write or grow methods will result in an allocation, or to know how much memory has been allocated so far. Fixes #26269. Change-Id: I391db45ae825011566b594836991e28135369a78 Reviewed-on: https://go-review.googlesource.com/122835 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
b2e66f1aec
commit
0566ab3383
2 changed files with 21 additions and 0 deletions
|
|
@ -50,6 +50,11 @@ func (b *Builder) String() string {
|
|||
// Len returns the number of accumulated bytes; b.Len() == len(b.String()).
|
||||
func (b *Builder) Len() int { return len(b.buf) }
|
||||
|
||||
// Cap returns the capacity of the builder's underlying byte slice. It is the
|
||||
// total space allocated for the string being built and includes any bytes
|
||||
// already written.
|
||||
func (b *Builder) Cap() int { return cap(b.buf) }
|
||||
|
||||
// Reset resets the Builder to be empty.
|
||||
func (b *Builder) Reset() {
|
||||
b.addr = nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue