diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2022-11-07 16:55:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 16:55:53 +0100 |
commit | f37bb587b6634435afb5069b2101cb4e0ff78d63 (patch) | |
tree | 9e6ace8591fff4e95f982304842f0bf8512bd612 /plumbing/format/objfile/writer.go | |
parent | 652bc83fe45c114440de41d7e0fecf3e4b9e517d (diff) | |
parent | a2c309de872dc18053acb186b1ec125d1f723a90 (diff) | |
download | go-git-f37bb587b6634435afb5069b2101cb4e0ff78d63.tar.gz |
Merge pull request #608 from pjbgf/optimise-zlib-reader
Optimise zlib reader and consolidate sync.Pools
Diffstat (limited to 'plumbing/format/objfile/writer.go')
-rw-r--r-- | plumbing/format/objfile/writer.go | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/plumbing/format/objfile/writer.go b/plumbing/format/objfile/writer.go index 248f81b..0d0f154 100644 --- a/plumbing/format/objfile/writer.go +++ b/plumbing/format/objfile/writer.go @@ -5,9 +5,9 @@ import ( "errors" "io" "strconv" - "sync" "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/utils/sync" ) var ( @@ -21,7 +21,7 @@ type Writer struct { raw io.Writer hasher plumbing.Hasher multi io.Writer - zlib io.WriteCloser + zlib *zlib.Writer closed bool pending int64 // number of unwritten bytes @@ -32,21 +32,13 @@ type Writer struct { // The returned Writer implements io.WriteCloser. Close should be called when // finished with the Writer. Close will not close the underlying io.Writer. func NewWriter(w io.Writer) *Writer { - zlib := zlibPool.Get().(*zlib.Writer) - zlib.Reset(w) - + zlib := sync.GetZlibWriter(w) return &Writer{ raw: w, zlib: zlib, } } -var zlibPool = sync.Pool{ - New: func() interface{} { - return zlib.NewWriter(nil) - }, -} - // WriteHeader writes the type and the size and prepares to accept the object's // contents. If an invalid t is provided, plumbing.ErrInvalidType is returned. If a // negative size is provided, ErrNegativeSize is returned. @@ -110,7 +102,7 @@ func (w *Writer) Hash() plumbing.Hash { // Calling Close does not close the wrapped io.Writer originally passed to // NewWriter. func (w *Writer) Close() error { - defer zlibPool.Put(w.zlib) + defer sync.PutZlibWriter(w.zlib) if err := w.zlib.Close(); err != nil { return err } |