contenthash: fix buffer reuse pool

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
v0.8
Tonis Tiigi 2020-07-18 14:51:35 -07:00
parent bd3354fea3
commit 0ed9eb77ce
1 changed files with 6 additions and 3 deletions

View File

@ -874,12 +874,15 @@ func ensureOriginMetadata(md *metadata.StorageItem) *metadata.StorageItem {
}
var pool32K = sync.Pool{
New: func() interface{} { return make([]byte, 32*1024) }, // 32K
New: func() interface{} {
buf := make([]byte, 32*1024) // 32K
return &buf
},
}
func poolsCopy(dst io.Writer, src io.Reader) (written int64, err error) {
buf := pool32K.Get().([]byte)
written, err = io.CopyBuffer(dst, src, buf)
buf := pool32K.Get().(*[]byte)
written, err = io.CopyBuffer(dst, src, *buf)
pool32K.Put(buf)
return
}