diff --git a/rpc_util.go b/rpc_util.go index a844d28f49d0..01e9c60b807f 100644 --- a/rpc_util.go +++ b/rpc_util.go @@ -803,7 +803,7 @@ func recv(p *parser, c baseCodec, s *transport.Stream, dc Decompressor, m interf if payInfo != nil { payInfo.uncompressedBytes = buf } else { - p.recvBufferPool.Put(&buf) + p.recvBufferPool.Put(buf) } return nil } diff --git a/shared_buffer_pool.go b/shared_buffer_pool.go index c3a5a9ac1f19..97af1857c296 100644 --- a/shared_buffer_pool.go +++ b/shared_buffer_pool.go @@ -35,7 +35,7 @@ type SharedBufferPool interface { Get(length int) []byte // Put returns a buffer to the pool. - Put(*[]byte) + Put([]byte) } // NewSharedBufferPool creates a simple SharedBufferPool with buckets @@ -68,8 +68,8 @@ func (p *simpleSharedBufferPool) Get(size int) []byte { return p.pools[p.poolIdx(size)].Get(size) } -func (p *simpleSharedBufferPool) Put(bs *[]byte) { - p.pools[p.poolIdx(cap(*bs))].Put(bs) +func (p *simpleSharedBufferPool) Put(bs []byte) { + p.pools[p.poolIdx(cap(bs))].Put(bs) } func (p *simpleSharedBufferPool) poolIdx(size int) int { @@ -119,23 +119,22 @@ type bufferPool struct { } func (p *bufferPool) Get(size int) []byte { - bs := p.Pool.Get().(*[]byte) + bs := p.Pool.Get().([]byte) - if cap(*bs) < size { + if cap(bs) < size { p.Pool.Put(bs) return make([]byte, size) } - return (*bs)[:size] + return (bs)[:size] } func newBytesPool(size int) simpleSharedBufferChildPool { return &bufferPool{ Pool: sync.Pool{ New: func() interface{} { - bs := make([]byte, size) - return &bs + return make([]byte, size) }, }, defaultSize: size, @@ -150,5 +149,5 @@ func (nopBufferPool) Get(length int) []byte { return make([]byte, length) } -func (nopBufferPool) Put(*[]byte) { +func (nopBufferPool) Put([]byte) { } diff --git a/shared_buffer_pool_test.go b/shared_buffer_pool_test.go index f5ed7c8314f1..1ecda754dfdb 100644 --- a/shared_buffer_pool_test.go +++ b/shared_buffer_pool_test.go @@ -42,7 +42,7 @@ func (s) TestSharedBufferPool(t *testing.T) { t.Fatalf("Expected buffer of length %d, got %d", l, len(bs)) } - p.Put(&bs) + p.Put(bs) } } }