Fix pkg/pools staticcheck SA6002
change bufferPool use pointer instead byte slice Signed-off-by: HuanHuan Ye <logindaveye@gmail.com>
This commit is contained in:
parent
5b57f41241
commit
8498ee7514
1 changed files with 5 additions and 6 deletions
|
@ -62,24 +62,23 @@ type bufferPool struct {
|
||||||
func newBufferPoolWithSize(size int) *bufferPool {
|
func newBufferPoolWithSize(size int) *bufferPool {
|
||||||
return &bufferPool{
|
return &bufferPool{
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} { return make([]byte, size) },
|
New: func() interface{} { s := make([]byte, size); return &s },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bp *bufferPool) Get() []byte {
|
func (bp *bufferPool) Get() *[]byte {
|
||||||
return bp.pool.Get().([]byte)
|
return bp.pool.Get().(*[]byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bp *bufferPool) Put(b []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)
|
|
||||||
bp.pool.Put(b)
|
bp.pool.Put(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy is a convenience wrapper which uses a buffer to avoid allocation in io.Copy.
|
// 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) {
|
func Copy(dst io.Writer, src io.Reader) (written int64, err error) {
|
||||||
buf := buffer32KPool.Get()
|
buf := buffer32KPool.Get()
|
||||||
written, err = io.CopyBuffer(dst, src, buf)
|
written, err = io.CopyBuffer(dst, src, *buf)
|
||||||
buffer32KPool.Put(buf)
|
buffer32KPool.Put(buf)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue