Do not return buffers with too big capacity to the pool

This commit is contained in:
Aliaksandr Valialkin
2016-06-23 22:41:46 +03:00
parent a1c2e6cf76
commit ea471ff2ce
+2 -3
View File
@@ -38,8 +38,7 @@ func (p *byteBufferPool) Acquire() *ByteBuffer {
}
func (p *byteBufferPool) Release(b *ByteBuffer) {
bSize := len(b.B)
idx := bitSize(bSize-1) - minBitSize
idx := bitSize(len(b.B)-1) - minBitSize
if idx < 0 {
idx = 0
} else if idx >= steps {
@@ -51,7 +50,7 @@ func (p *byteBufferPool) Release(b *ByteBuffer) {
}
maxSize := int(atomic.LoadUint64(&p.maxSize))
if maxSize > 0 && bSize <= maxSize {
if maxSize > 0 && cap(b.B) <= maxSize {
b.B = b.B[:0]
p.pool.Put(b)
}