fix golint issues in core/iox (#488)

This commit is contained in:
Kevin Wan
2021-02-19 18:40:26 +08:00
committed by GitHub
parent 0c094cb2d7
commit 1f92bfde6a
5 changed files with 17 additions and 0 deletions

View File

@@ -5,11 +5,13 @@ import (
"sync"
)
// A BufferPool is a pool to buffer bytes.Buffer objects.
type BufferPool struct {
capability int
pool *sync.Pool
}
// NewBufferPool returns a BufferPool.
func NewBufferPool(capability int) *BufferPool {
return &BufferPool{
capability: capability,
@@ -21,12 +23,14 @@ func NewBufferPool(capability int) *BufferPool {
}
}
// Get returns a bytes.Buffer object from bp.
func (bp *BufferPool) Get() *bytes.Buffer {
buf := bp.pool.Get().(*bytes.Buffer)
buf.Reset()
return buf
}
// Put returns buf into bp.
func (bp *BufferPool) Put(buf *bytes.Buffer) {
if buf.Cap() < bp.capability {
bp.pool.Put(buf)