diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2022-11-07 16:53:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 16:53:56 +0100 |
commit | 652bc83fe45c114440de41d7e0fecf3e4b9e517d (patch) | |
tree | a784f0a4b677abc00247638e600f5efef1c44dfc /plumbing/format/packfile/scanner.go | |
parent | 08cffa1efade914020497a73907763e8d3707a77 (diff) | |
parent | ffa7e69efb8c4ba8d4e08ec4c65e49e2228fd88b (diff) | |
download | go-git-652bc83fe45c114440de41d7e0fecf3e4b9e517d.tar.gz |
Merge pull request #602 from pjbgf/parse-optimisation
Parse optimisations
Diffstat (limited to 'plumbing/format/packfile/scanner.go')
-rw-r--r-- | plumbing/format/packfile/scanner.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/plumbing/format/packfile/scanner.go b/plumbing/format/packfile/scanner.go index 45d480c..b655594 100644 --- a/plumbing/format/packfile/scanner.go +++ b/plumbing/format/packfile/scanner.go @@ -346,15 +346,17 @@ func (s *Scanner) copyObject(w io.Writer) (n int64, err error) { } defer ioutil.CheckClose(zr, &err) - buf := byteSlicePool.Get().([]byte) + bufp := byteSlicePool.Get().(*[]byte) + buf := *bufp n, err = io.CopyBuffer(w, zr, buf) - byteSlicePool.Put(buf) + byteSlicePool.Put(bufp) return } var byteSlicePool = sync.Pool{ New: func() interface{} { - return make([]byte, 32*1024) + b := make([]byte, 32*1024) + return &b }, } @@ -387,9 +389,11 @@ func (s *Scanner) Checksum() (plumbing.Hash, error) { // Close reads the reader until io.EOF func (s *Scanner) Close() error { - buf := byteSlicePool.Get().([]byte) + bufp := byteSlicePool.Get().(*[]byte) + buf := *bufp _, err := io.CopyBuffer(stdioutil.Discard, s.r, buf) - byteSlicePool.Put(buf) + byteSlicePool.Put(bufp) + return err } |