Skip to content

Commit 79c0f24

Browse files
committed
reuse slice with max cap
Signed-off-by: Alan Protasio <[email protected]>
1 parent 4ec4cee commit 79c0f24

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pkg/util/grpcencoding/snappyblock/snappyblock.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ func newCompressor() *compressor {
2727
New: func() interface{} {
2828
return &reader{
2929
pool: &c.readersPool,
30-
cbuff: bytes.NewBuffer(make([]byte, 0, 512)),
30+
cbuff: bytes.NewBuffer(make([]byte, 512, 512)),
3131
}
3232
},
3333
}
3434
c.writersPool = sync.Pool{
3535
New: func() interface{} {
3636
return &writeCloser{
3737
pool: &c.writersPool,
38-
buff: bytes.NewBuffer(make([]byte, 0, 512)),
38+
buff: bytes.NewBuffer(make([]byte, 512, 512)),
3939
}
4040
},
4141
}
@@ -95,7 +95,7 @@ func (w *writeCloser) Write(p []byte) (n int, err error) {
9595
func (w *writeCloser) Close() error {
9696
defer func() {
9797
w.buff.Reset()
98-
w.dst = w.dst[:0]
98+
w.dst = w.dst[0:cap(w.dst)]
9999
w.pool.Put(w)
100100
}()
101101

0 commit comments

Comments
 (0)