From 8498ee7514cfb166197f637cc3dd69194de5f16b Mon Sep 17 00:00:00 2001 From: HuanHuan Ye Date: Mon, 30 Sep 2019 12:19:03 +0800 Subject: [PATCH] Fix pkg/pools staticcheck SA6002 change bufferPool use pointer instead byte slice Signed-off-by: HuanHuan Ye --- pkg/pools/pools.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/pools/pools.go b/pkg/pools/pools.go index 3b978fd3b5..3792c67a9e 100644 --- a/pkg/pools/pools.go +++ b/pkg/pools/pools.go @@ -62,24 +62,23 @@ type bufferPool struct { func newBufferPoolWithSize(size int) *bufferPool { return &bufferPool{ pool: sync.Pool{ - New: func() interface{} { return make([]byte, size) }, + New: func() interface{} { s := make([]byte, size); return &s }, }, } } -func (bp *bufferPool) Get() []byte { - return bp.pool.Get().([]byte) +func (bp *bufferPool) Get() *[]byte { + return bp.pool.Get().(*[]byte) } -func (bp *bufferPool) Put(b []byte) { - //nolint:staticcheck // TODO changing this to a pointer makes tests fail. Investigate if we should change or not (otherwise remove this TODO) +func (bp *bufferPool) Put(b *[]byte) { bp.pool.Put(b) } // Copy is a convenience wrapper which uses a buffer to avoid allocation in io.Copy. func Copy(dst io.Writer, src io.Reader) (written int64, err error) { buf := buffer32KPool.Get() - written, err = io.CopyBuffer(dst, src, buf) + written, err = io.CopyBuffer(dst, src, *buf) buffer32KPool.Put(buf) return }