From bcc296ea5d8f20e078036593ee56e094b38c0faf Mon Sep 17 00:00:00 2001 From: Jeremy Stribling Date: Mon, 30 Oct 2017 15:57:11 -0700 Subject: packfile: use buffer pool for diffs --- plumbing/format/packfile/diff_delta.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'plumbing') 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 { -- cgit