diff options
author | Paulo Gomes <pjbgf@linux.com> | 2022-10-26 18:12:39 +0100 |
---|---|---|
committer | Paulo Gomes <pjbgf@linux.com> | 2022-11-07 14:41:07 +0000 |
commit | 123cdde6f2f6282cb779e03745d384833ac1265b (patch) | |
tree | dc20c37ece501c3d66935c3832269393f2c18f63 /worktree.go | |
parent | 08cffa1efade914020497a73907763e8d3707a77 (diff) | |
download | go-git-123cdde6f2f6282cb779e03745d384833ac1265b.tar.gz |
Use Sync.Pool pointers to optimise memory usage
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Diffstat (limited to 'worktree.go')
-rw-r--r-- | worktree.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/worktree.go b/worktree.go index c974aed..98116ca 100644 --- a/worktree.go +++ b/worktree.go @@ -534,7 +534,8 @@ func (w *Worktree) checkoutChangeRegularFile(name string, var copyBufferPool = sync.Pool{ New: func() interface{} { - return make([]byte, 32*1024) + b := make([]byte, 32*1024) + return &b }, } @@ -561,9 +562,10 @@ func (w *Worktree) checkoutFile(f *object.File) (err error) { } defer ioutil.CheckClose(to, &err) - buf := copyBufferPool.Get().([]byte) + bufp := copyBufferPool.Get().(*[]byte) + buf := *bufp _, err = io.CopyBuffer(to, from, buf) - copyBufferPool.Put(buf) + copyBufferPool.Put(bufp) return } |