mirror of
https://github.com/minio/minio.git
synced 2025-02-03 09:55:59 -05:00
Always return slice with cap (#19395)
Documentation promised this - so we should do it as well. Try to get a buffer and stash if it isn't big enough.
This commit is contained in:
parent
4f660a8eb7
commit
912bbb2f1d
@ -87,13 +87,20 @@ var GetByteBuffer = func() []byte {
|
|||||||
|
|
||||||
// GetByteBufferCap returns a length 0 byte buffer with at least the given capacity.
|
// GetByteBufferCap returns a length 0 byte buffer with at least the given capacity.
|
||||||
func GetByteBufferCap(wantSz int) []byte {
|
func GetByteBufferCap(wantSz int) []byte {
|
||||||
switch {
|
if wantSz < defaultBufferSize {
|
||||||
case wantSz <= defaultBufferSize:
|
b := GetByteBuffer()[:0]
|
||||||
return GetByteBuffer()[:0]
|
if cap(b) >= wantSz {
|
||||||
case wantSz <= maxBufferSize:
|
return b
|
||||||
|
}
|
||||||
|
PutByteBuffer(b)
|
||||||
|
}
|
||||||
|
if wantSz <= maxBufferSize {
|
||||||
b := *internal32KByteBuffer.Get().(*[]byte)
|
b := *internal32KByteBuffer.Get().(*[]byte)
|
||||||
|
if cap(b) >= wantSz {
|
||||||
return b[:0]
|
return b[:0]
|
||||||
}
|
}
|
||||||
|
internal32KByteBuffer.Put(&b)
|
||||||
|
}
|
||||||
return make([]byte, 0, wantSz)
|
return make([]byte, 0, wantSz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user