Skip to content

Commit

Permalink
Merge pull request go-git#7 from dsymonds/master
Browse files Browse the repository at this point in the history
plumbing/object: avoid O(N^2) string building when decoding commit message
  • Loading branch information
mcuadros authored Mar 9, 2020
2 parents 586d45a + d3dd84b commit 042981b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions plumbing/object/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 042981b

Please sign in to comment.