From c1086eafdf45fe85ce0050890da6b42a146c7ddc Mon Sep 17 00:00:00 2001 From: Nao YONASHIRO Date: Sat, 29 Jun 2019 02:04:09 +0900 Subject: refactor: use bufPool Signed-off-by: Nao YONASHIRO --- plumbing/format/packfile/patch_delta.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/plumbing/format/packfile/patch_delta.go b/plumbing/format/packfile/patch_delta.go index 45e589e..7840f17 100644 --- a/plumbing/format/packfile/patch_delta.go +++ b/plumbing/format/packfile/patch_delta.go @@ -3,7 +3,6 @@ package packfile import ( "bytes" "errors" - "sync" "gopkg.in/src-d/go-git.v4/plumbing" ) @@ -15,12 +14,6 @@ import ( const deltaSizeMin = 4 -var bytesBufferPool = sync.Pool{ - New: func() interface{} { - return &bytes.Buffer{} - }, -} - // ApplyDelta writes to target the result of applying the modification deltas in delta to base. func ApplyDelta(target, base plumbing.EncodedObject, delta []byte) error { r, err := base.Reader() @@ -33,11 +26,9 @@ func ApplyDelta(target, base plumbing.EncodedObject, delta []byte) error { return err } - buf := bytesBufferPool.Get().(*bytes.Buffer) - defer func() { - buf.Reset() - bytesBufferPool.Put(buf) - } () + buf := bufPool.Get().(*bytes.Buffer) + defer bufPool.Put(buf) + buf.Reset() _, err = buf.ReadFrom(r) if err != nil { return err -- cgit