mirror of
https://github.com/minio/minio.git
synced 2025-02-03 01:46:00 -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,12 +87,19 @@ var GetByteBuffer = func() []byte {
|
||||
|
||||
// GetByteBufferCap returns a length 0 byte buffer with at least the given capacity.
|
||||
func GetByteBufferCap(wantSz int) []byte {
|
||||
switch {
|
||||
case wantSz <= defaultBufferSize:
|
||||
return GetByteBuffer()[:0]
|
||||
case wantSz <= maxBufferSize:
|
||||
if wantSz < defaultBufferSize {
|
||||
b := GetByteBuffer()[:0]
|
||||
if cap(b) >= wantSz {
|
||||
return b
|
||||
}
|
||||
PutByteBuffer(b)
|
||||
}
|
||||
if wantSz <= maxBufferSize {
|
||||
b := *internal32KByteBuffer.Get().(*[]byte)
|
||||
return b[:0]
|
||||
if cap(b) >= wantSz {
|
||||
return b[:0]
|
||||
}
|
||||
internal32KByteBuffer.Put(&b)
|
||||
}
|
||||
return make([]byte, 0, wantSz)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user