diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2017-10-30 15:57:11 -0700 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-10-30 16:08:08 -0700 |
commit | bcc296ea5d8f20e078036593ee56e094b38c0faf (patch) | |
tree | 659bf9a237a19f539b90f684338b6ca4ec7ea76d /plumbing/format/packfile | |
parent | 50732e34e5304e3a32e87a8937faad4d7b845e50 (diff) | |
download | go-git-bcc296ea5d8f20e078036593ee56e094b38c0faf.tar.gz |
packfile: use buffer pool for diffs
Diffstat (limited to 'plumbing/format/packfile')
-rw-r--r-- | plumbing/format/packfile/diff_delta.go | 17 |
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 { |