diff options
author | Nao YONASHIRO <owan.orisano@gmail.com> | 2019-06-28 03:36:52 +0900 |
---|---|---|
committer | Nao YONASHIRO <owan.orisano@gmail.com> | 2019-07-31 00:23:33 +0900 |
commit | 509b128eadef10d52c5cb73b6f56d426d677ae6a (patch) | |
tree | b394c3edce9877bc31b5885ff465f87e6b76809c /plumbing | |
parent | 6241d0e70427cb0db4ca00182717af88f638268c (diff) | |
download | go-git-509b128eadef10d52c5cb73b6f56d426d677ae6a.tar.gz |
feat: avoid ioutil.ReadAll on ApplyDelta
Signed-off-by: Nao YONASHIRO <owan.orisano@gmail.com>
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/format/packfile/patch_delta.go | 17 |
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 { |