fix(model): correct bufferpool handling; simplify (#10113)
The copier routine refactor resulted in bad buffer pool handling, putting a buffer back into the pool twice. This simplifies and removes the danger prone Upgrade() method.
This commit is contained in:
@@ -59,7 +59,7 @@ func (p *bufferPool) Get(size int) []byte {
|
||||
}
|
||||
|
||||
// Put makes the given byte slice available again in the global pool.
|
||||
// You must only Put() slices that were returned by Get() or Upgrade().
|
||||
// You must only Put() slices that were returned by Get().
|
||||
func (p *bufferPool) Put(bs []byte) {
|
||||
// Don't buffer slices outside of our pool range
|
||||
if cap(bs) > MaxBlockSize || cap(bs) < MinBlockSize {
|
||||
@@ -72,20 +72,6 @@ func (p *bufferPool) Put(bs []byte) {
|
||||
p.pools[bkt].Put(&bs)
|
||||
}
|
||||
|
||||
// Upgrade grows the buffer to the requested size, while attempting to reuse
|
||||
// it if possible.
|
||||
func (p *bufferPool) Upgrade(bs []byte, size int) []byte {
|
||||
if cap(bs) >= size {
|
||||
// Reslicing is enough, lets go!
|
||||
return bs[:size]
|
||||
}
|
||||
|
||||
// It was too small. But it pack into the pool and try to get another
|
||||
// buffer.
|
||||
p.Put(bs)
|
||||
return p.Get(size)
|
||||
}
|
||||
|
||||
// getBucketForLen returns the bucket where we should get a slice of a
|
||||
// certain length. Each bucket is guaranteed to hold slices that are
|
||||
// precisely the block size for that bucket, so if the block size is larger
|
||||
|
||||
Reference in New Issue
Block a user