aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Cobo <toqueteos@gmail.com>2015-05-29 11:38:46 +0200
committerCarlos Cobo <toqueteos@gmail.com>2015-06-04 16:09:03 +0200
commitb977a025ca21e3b5ca123d8093bd7917694f6da7 (patch)
treebc036af7f2ca6d8544f852365479b4da15e1f836
parent35b585759cbf29f8ec428ef89da20705d59f99ec (diff)
downloadgo-git-b977a025ca21e3b5ca123d8093bd7917694f6da7.tar.gz
Remove not used zlib fragment.
NewTree is called with the already deflated contents, there's no need to always fail creating a `zlib.NewReader` and waste memory with a new buffer we are just about to destroy.
-rw-r--r--packfile/objects.go19
1 files changed, 3 insertions, 16 deletions
diff --git a/packfile/objects.go b/packfile/objects.go
index 3c77a33..a73b8c3 100644
--- a/packfile/objects.go
+++ b/packfile/objects.go
@@ -2,11 +2,9 @@ package packfile
import (
"bytes"
- "compress/zlib"
"crypto/sha1"
"encoding/hex"
"fmt"
- "io/ioutil"
"strconv"
"time"
)
@@ -148,24 +146,13 @@ type TreeEntry struct {
Hash string
}
-func NewTree(b []byte) (*Tree, error) {
- o := &Tree{hash: calculateHash("tree", b)}
+func NewTree(body []byte) (*Tree, error) {
+ o := &Tree{hash: calculateHash("tree", body)}
- if len(b) == 0 {
+ if len(body) == 0 {
return o, nil
}
- zr, e := zlib.NewReader(bytes.NewBuffer(b))
- if e == nil {
- defer zr.Close()
- var err error
- b, err = ioutil.ReadAll(zr)
- if err != nil {
- return nil, err
- }
- }
-
- body := b
for {
split := bytes.SplitN(body, []byte{0}, 2)
split1 := bytes.SplitN(split[0], []byte{' '}, 2)