mirror of
https://github.com/valyala/bytebufferpool.git
synced 2026-06-14 13:26:35 +03:00
Do not return buffers with too big capacity to the pool
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user