aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao YONASHIRO <owan.orisano@gmail.com>2019-06-28 03:36:52 +0900
committerNao YONASHIRO <owan.orisano@gmail.com>2019-07-31 00:23:33 +0900
commit509b128eadef10d52c5cb73b6f56d426d677ae6a (patch)
treeb394c3edce9877bc31b5885ff465f87e6b76809c
parent6241d0e70427cb0db4ca00182717af88f638268c (diff)
downloadgo-git-509b128eadef10d52c5cb73b6f56d426d677ae6a.tar.gz
feat: avoid ioutil.ReadAll on ApplyDelta
Signed-off-by: Nao YONASHIRO <owan.orisano@gmail.com>
-rw-r--r--plumbing/format/packfile/patch_delta.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/plumbing/format/packfile/patch_delta.go b/plumbing/format/packfile/patch_delta.go
index a972f1c..45e589e 100644
--- a/plumbing/format/packfile/patch_delta.go
+++ b/plumbing/format/packfile/patch_delta.go
@@ -1,8 +1,9 @@
package packfile
import (
+ "bytes"
"errors"
- "io/ioutil"
+ "sync"
"gopkg.in/src-d/go-git.v4/plumbing"
)
@@ -14,6 +15,12 @@ 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()
@@ -26,10 +33,16 @@ func ApplyDelta(target, base plumbing.EncodedObject, delta []byte) error {
return err
}
- src, err := ioutil.ReadAll(r)
+ buf := bytesBufferPool.Get().(*bytes.Buffer)
+ defer func() {
+ buf.Reset()
+ bytesBufferPool.Put(buf)
+ } ()
+ _, err = buf.ReadFrom(r)
if err != nil {
return err
}
+ src := buf.Bytes()
dst, err := PatchDelta(src, delta)
if err != nil {