Skip to content

Commit e632408

Browse files
authored
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.
1 parent f8e7977 commit e632408

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

zstd/zip.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ func (r *pooledZipReader) Close() error {
6464
}
6565

6666
type pooledZipWriter struct {
67-
mu sync.Mutex // guards Close and Read
68-
enc *Encoder
67+
mu sync.Mutex // guards Close and Read
68+
enc *Encoder
69+
pool *sync.Pool
6970
}
7071

7172
func (w *pooledZipWriter) Write(p []byte) (n int, err error) {
@@ -83,7 +84,7 @@ func (w *pooledZipWriter) Close() error {
8384
var err error
8485
if w.enc != nil {
8586
err = w.enc.Close()
86-
zipReaderPool.Put(w.enc)
87+
w.pool.Put(w.enc)
8788
w.enc = nil
8889
}
8990
return err
@@ -104,7 +105,7 @@ func ZipCompressor(opts ...EOption) func(w io.Writer) (io.WriteCloser, error) {
104105
return nil, err
105106
}
106107
}
107-
return &pooledZipWriter{enc: enc}, nil
108+
return &pooledZipWriter{enc: enc, pool: &pool}, nil
108109
}
109110
}
110111

0 commit comments

Comments
 (0)