File tree 1 file changed +12
-5
lines changed
1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,9 @@ type Buffer struct {
23
23
off int // read at &buf[off], write at &buf[len(buf)]
24
24
lastRead readOp // last read operation, so that Unread* can work correctly.
25
25
26
- // This is padding for Buffer to cache lines to avoid false sharing.
27
- _ [cpu .BufferPaddingSize ]byte
26
+ // memory to hold first slice; helps small buffers (Printf) avoid allocation.
27
+ // Also it's padding for Buffer to cache lines to avoid false sharing.
28
+ bootstrap [cpu .BufferPaddingSize ]byte
28
29
}
29
30
30
31
// The readOp constants describe the last action performed on
@@ -128,9 +129,15 @@ func (b *Buffer) grow(n int) int {
128
129
if i , ok := b .tryGrowByReslice (n ); ok {
129
130
return i
130
131
}
131
- if b .buf == nil && n <= smallBufferSize {
132
- b .buf = make ([]byte , n , smallBufferSize )
133
- return 0
132
+ if b .buf == nil {
133
+ switch {
134
+ case n <= cpu .BufferPaddingSize :
135
+ buf = b .bootstrap [0 :]
136
+ return 0
137
+ case n <= smallBufferSize :
138
+ b .buf = make ([]byte , n , smallBufferSize )
139
+ return 0
140
+ }
134
141
}
135
142
c := cap (b .buf )
136
143
if n <= c / 2 - m {
You can’t perform that action at this time.
0 commit comments