aboutsummaryrefslogtreecommitdiff
path: root/src/bytes/buffer.go
diff options
context:
space:
mode:
authorFilippo Valsorda <filippo@golang.org>2018-10-15 17:09:34 -0400
committerFilippo Valsorda <filippo@golang.org>2018-10-15 17:09:34 -0400
commit623650b27aa42dd2ccd20fc4a79f8fe7b8559987 (patch)
treebfafa16d1bfd57fc1d9831c22e6e236be3d52281 /src/bytes/buffer.go
parent36c789b1fd72af5ff6e756794597a3a85e069998 (diff)
parent1961d8d72a53e780effa18bfa8dbe4e4282df0b2 (diff)
downloadgo-623650b27aa42dd2ccd20fc4a79f8fe7b8559987.tar.xz
[dev.boringcrypto] all: merge master into dev.boringcrypto
Change-Id: I218ba1b89a2df6e4335c6a5846889d9a04affe5d
Diffstat (limited to 'src/bytes/buffer.go')
-rw-r--r--src/bytes/buffer.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/bytes/buffer.go b/src/bytes/buffer.go
index 14c5bc38d6..087cc0e427 100644
--- a/src/bytes/buffer.go
+++ b/src/bytes/buffer.go
@@ -12,13 +12,15 @@ import (
"unicode/utf8"
)
+// smallBufferSize is an initial allocation minimal capacity.
+const smallBufferSize = 64
+
// A Buffer is a variable-sized buffer of bytes with Read and Write methods.
// The zero value for Buffer is an empty buffer ready to use.
type Buffer struct {
- buf []byte // contents are the bytes buf[off : len(buf)]
- off int // read at &buf[off], write at &buf[len(buf)]
- bootstrap [64]byte // memory to hold first slice; helps small buffers avoid allocation.
- lastRead readOp // last read operation, so that Unread* can work correctly.
+ buf []byte // contents are the bytes buf[off : len(buf)]
+ off int // read at &buf[off], write at &buf[len(buf)]
+ lastRead readOp // last read operation, so that Unread* can work correctly.
// FIXME: it would be advisable to align Buffer to cachelines to avoid false
// sharing.
@@ -125,9 +127,8 @@ func (b *Buffer) grow(n int) int {
if i, ok := b.tryGrowByReslice(n); ok {
return i
}
- // Check if we can make use of bootstrap array.
- if b.buf == nil && n <= len(b.bootstrap) {
- b.buf = b.bootstrap[:n]
+ if b.buf == nil && n <= smallBufferSize {
+ b.buf = make([]byte, n, smallBufferSize)
return 0
}
c := cap(b.buf)