From e63240850d8a60abf70b937014efb1148cdecd6e Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Mon, 30 Aug 2021 10:57:58 +0200 Subject: [PATCH] zstd: pooledZipWriter should return Writers to the same pool (#426) This code was previously Get'ing objects from one pool and later Put'ing them to a different pool, so they were never reused. --- zstd/zip.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/zstd/zip.go b/zstd/zip.go index 9325b928ae..967f29b312 100644 --- a/zstd/zip.go +++ b/zstd/zip.go @@ -64,8 +64,9 @@ func (r *pooledZipReader) Close() error { } type pooledZipWriter struct { - mu sync.Mutex // guards Close and Read - enc *Encoder + mu sync.Mutex // guards Close and Read + enc *Encoder + pool *sync.Pool } func (w *pooledZipWriter) Write(p []byte) (n int, err error) { @@ -83,7 +84,7 @@ func (w *pooledZipWriter) Close() error { var err error if w.enc != nil { err = w.enc.Close() - zipReaderPool.Put(w.enc) + w.pool.Put(w.enc) w.enc = nil } return err @@ -104,7 +105,7 @@ func ZipCompressor(opts ...EOption) func(w io.Writer) (io.WriteCloser, error) { return nil, err } } - return &pooledZipWriter{enc: enc}, nil + return &pooledZipWriter{enc: enc, pool: &pool}, nil } }