aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/scanner.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2022-10-26 18:12:39 +0100
committerPaulo Gomes <pjbgf@linux.com>2022-11-07 14:41:07 +0000
commit123cdde6f2f6282cb779e03745d384833ac1265b (patch)
treedc20c37ece501c3d66935c3832269393f2c18f63 /plumbing/format/packfile/scanner.go
parent08cffa1efade914020497a73907763e8d3707a77 (diff)
downloadgo-git-123cdde6f2f6282cb779e03745d384833ac1265b.tar.gz
Use Sync.Pool pointers to optimise memory usage
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Diffstat (limited to 'plumbing/format/packfile/scanner.go')
-rw-r--r--plumbing/format/packfile/scanner.go14
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
}