aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/objfile
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2022-11-07 16:53:56 +0100
committerGitHub <noreply@github.com>2022-11-07 16:53:56 +0100
commit652bc83fe45c114440de41d7e0fecf3e4b9e517d (patch)
treea784f0a4b677abc00247638e600f5efef1c44dfc /plumbing/format/objfile
parent08cffa1efade914020497a73907763e8d3707a77 (diff)
parentffa7e69efb8c4ba8d4e08ec4c65e49e2228fd88b (diff)
downloadgo-git-652bc83fe45c114440de41d7e0fecf3e4b9e517d.tar.gz
Merge pull request #602 from pjbgf/parse-optimisation
Parse optimisations
Diffstat (limited to 'plumbing/format/objfile')
-rw-r--r--plumbing/format/objfile/writer.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/plumbing/format/objfile/writer.go b/plumbing/format/objfile/writer.go
index 2a96a43..248f81b 100644
--- a/plumbing/format/objfile/writer.go
+++ b/plumbing/format/objfile/writer.go
@@ -5,6 +5,7 @@ import (
"errors"
"io"
"strconv"
+ "sync"
"github.com/go-git/go-git/v5/plumbing"
)
@@ -18,9 +19,9 @@ var (
// not close the underlying io.Writer.
type Writer struct {
raw io.Writer
- zlib io.WriteCloser
hasher plumbing.Hasher
multi io.Writer
+ zlib io.WriteCloser
closed bool
pending int64 // number of unwritten bytes
@@ -31,12 +32,21 @@ 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)
+
return &Writer{
raw: w,
- zlib: zlib.NewWriter(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.
@@ -100,6 +110,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)
if err := w.zlib.Close(); err != nil {
return err
}