aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/diff_delta.go
diff options
context:
space:
mode:
authorMiguel Molina <miguel@erizocosmi.co>2017-09-04 18:23:26 +0200
committerMiguel Molina <miguel@erizocosmi.co>2017-09-04 18:23:26 +0200
commit6a46a7eb543789c7012bf0f964e1b6b38eca150c (patch)
tree13283ed091249f601ceacd7c64a3467c5f4eac78 /plumbing/format/packfile/diff_delta.go
parent770800d980ba7e0af40502324d15ed50445a3291 (diff)
downloadgo-git-6a46a7eb543789c7012bf0f964e1b6b38eca150c.tar.gz
packfile: improve performance a little by reducing gc pressure
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Diffstat (limited to 'plumbing/format/packfile/diff_delta.go')
-rw-r--r--plumbing/format/packfile/diff_delta.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/plumbing/format/packfile/diff_delta.go b/plumbing/format/packfile/diff_delta.go
index 60a04d9..7e9f822 100644
--- a/plumbing/format/packfile/diff_delta.go
+++ b/plumbing/format/packfile/diff_delta.go
@@ -60,13 +60,15 @@ func GetDelta(base, target plumbing.EncodedObject) (plumbing.EncodedObject, erro
// DiffDelta returns the delta that transforms src into tgt.
func DiffDelta(src []byte, tgt []byte) []byte {
- buf := bytes.NewBuffer(nil)
+ buf := bufPool.Get().(*bytes.Buffer)
+ buf.Reset()
buf.Write(deltaEncodeSize(len(src)))
buf.Write(deltaEncodeSize(len(tgt)))
sindex := initMatch(src)
- ibuf := bytes.NewBuffer(nil)
+ ibuf := bufPool.Get().(*bytes.Buffer)
+ ibuf.Reset()
for i := 0; i < len(tgt); i++ {
offset, l := findMatch(src, tgt, sindex, i)
@@ -93,8 +95,12 @@ func DiffDelta(src []byte, tgt []byte) []byte {
}
encodeInsertOperation(ibuf, buf)
+ bytes := buf.Bytes()
+
+ bufPool.Put(buf)
+ bufPool.Put(ibuf)
- return buf.Bytes()
+ return bytes
}
func encodeInsertOperation(ibuf, buf *bytes.Buffer) {