Skip to content

Commit

Permalink
zstd: pooledZipWriter should return Writers to the same pool (#426)
Browse files Browse the repository at this point in the history
This code was previously Get'ing objects from one pool and later
Put'ing them to a different pool, so they were never reused.
  • Loading branch information
mostynb committed Aug 30, 2021
1 parent f8e7977 commit e632408
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions zstd/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
}
}

Expand Down

0 comments on commit e632408

Please sign in to comment.