Skip to content

Commit

Permalink
Merge pull request moby#40009 from yedamao/fix-pkg-pool
Browse files Browse the repository at this point in the history
Fix pkg/pools staticcheck SA6002
  • Loading branch information
tiborvass authored Sep 30, 2019
2 parents 58653d0 + 8498ee7 commit 0f9c4fa
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/pools/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0f9c4fa

Please sign in to comment.