1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #7602 from unclejack/tarsum_garbage_reduction

pkg/tarsum: avoid buf2 allocation in Read
This commit is contained in:
Vincent Batts 2014-08-19 13:50:15 -04:00
commit 487af281bf

View file

@ -23,6 +23,7 @@ type TarSum struct {
gz writeCloseFlusher
bufTar *bytes.Buffer
bufGz *bytes.Buffer
bufData [8192]byte
h hash.Hash
sums map[string]string
currentFile string
@ -92,7 +93,12 @@ func (ts *TarSum) Read(buf []byte) (int, error) {
if ts.finished {
return ts.bufGz.Read(buf)
}
buf2 := make([]byte, len(buf), cap(buf))
var buf2 []byte
if len(buf) > 8192 {
buf2 = make([]byte, len(buf), cap(buf))
} else {
buf2 = ts.bufData[:len(buf)-1]
}
n, err := ts.tarR.Read(buf2)
if err != nil {