aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-10-31 17:11:30 +0100
committerGitHub <noreply@github.com>2017-10-31 17:11:30 +0100
commitf98cab33c958ff4fbbf5d6b1eb61284ce5db9d0f (patch)
tree5037722048d833c25139ce9b7fde97a480f5e047 /plumbing/format/packfile
parent0d6968197857d7ca7911cfd07925cf0a079b41fa (diff)
parentbcc296ea5d8f20e078036593ee56e094b38c0faf (diff)
downloadgo-git-f98cab33c958ff4fbbf5d6b1eb61284ce5db9d0f.tar.gz
Merge pull request #631 from keybase/strib/use-bytes-pool-for-diffs
packfile: use buffer pool for diffs
Diffstat (limited to 'plumbing/format/packfile')
-rw-r--r--plumbing/format/packfile/diff_delta.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/plumbing/format/packfile/diff_delta.go b/plumbing/format/packfile/diff_delta.go
index d4b207a..4d56dc1 100644
--- a/plumbing/format/packfile/diff_delta.go
+++ b/plumbing/format/packfile/diff_delta.go
@@ -2,7 +2,6 @@ package packfile
import (
"bytes"
- "io/ioutil"
"gopkg.in/src-d/go-git.v4/plumbing"
)
@@ -33,22 +32,32 @@ func getDelta(index *deltaIndex, base, target plumbing.EncodedObject) (plumbing.
if err != nil {
return nil, err
}
+ defer br.Close()
tr, err := target.Reader()
if err != nil {
return nil, err
}
+ defer tr.Close()
- bb, err := ioutil.ReadAll(br)
+ bb := bufPool.Get().(*bytes.Buffer)
+ bb.Reset()
+ defer bufPool.Put(bb)
+
+ _, err = bb.ReadFrom(br)
if err != nil {
return nil, err
}
- tb, err := ioutil.ReadAll(tr)
+ tb := bufPool.Get().(*bytes.Buffer)
+ tb.Reset()
+ defer bufPool.Put(tb)
+
+ _, err = tb.ReadFrom(tr)
if err != nil {
return nil, err
}
- db := diffDelta(index, bb, tb)
+ db := diffDelta(index, bb.Bytes(), tb.Bytes())
delta := &plumbing.MemoryObject{}
_, err = delta.Write(db)
if err != nil {