aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-03-10 00:04:36 +0100
committerGitHub <noreply@github.com>2020-03-10 00:04:36 +0100
commit042981be1fc9aa9b182c3c35b7e2258845e13f49 (patch)
treecc0f8a306b3852ffb4e3fe7f276ba789b5c59ad5 /plumbing/object
parent586d45a14f4646e3d6280cb723d2cfb152a6a9f8 (diff)
parentd3dd84b7108ed4a062dced6e1d2d5dd4537c9e57 (diff)
downloadgo-git-042981be1fc9aa9b182c3c35b7e2258845e13f49.tar.gz
Merge pull request #7 from dsymonds/master
plumbing/object: avoid O(N^2) string building when decoding commit message
Diffstat (limited to 'plumbing/object')
-rw-r--r--plumbing/object/commit.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go
index 6b50934..eb86a01 100644
--- a/plumbing/object/commit.go
+++ b/plumbing/object/commit.go
@@ -177,6 +177,7 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
var message bool
var pgpsig bool
+ var msgbuf bytes.Buffer
for {
line, err := r.ReadBytes('\n')
if err != nil && err != io.EOF {
@@ -221,13 +222,15 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
pgpsig = true
}
} else {
- c.Message += string(line)
+ msgbuf.Write(line)
}
if err == io.EOF {
- return nil
+ break
}
}
+ c.Message = msgbuf.String()
+ return nil
}
// Encode transforms a Commit into a plumbing.EncodedObject.