Don't zero buffer if big enough (#13877)

Only append zeroed bytes when we don't have enough space anyway.
This commit is contained in:
Klaus Post 2021-12-10 13:08:10 -08:00 committed by GitHub
parent a02e17f15c
commit 81e43b87c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -658,7 +658,12 @@ func readXLMetaNoData(r io.Reader, size int64) ([]byte, error) {
return io.ErrUnexpectedEOF
}
extra := n - has
if int64(cap(buf)) >= n {
// Extend since we have enough space.
buf = buf[:n]
} else {
buf = append(buf, make([]byte, extra)...)
}
_, err := io.ReadFull(r, buf[has:])
if err != nil {
if errors.Is(err, io.EOF) {