Skip to content

Commit

Permalink
fix: avoid allocating cids (ipfs#348)
Browse files Browse the repository at this point in the history
This commit was moved from ipfs/go-bitswap@906b2fb
  • Loading branch information
Stebalien authored Apr 13, 2020
1 parent 2fb1ad8 commit a1b6ce9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bitswap/message/pb/cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func (c Cid) Marshal() ([]byte, error) {
}

func (c *Cid) MarshalTo(data []byte) (int, error) {
return copy(data[:c.Size()], c.Cid.Bytes()), nil
// intentionally using KeyString here to avoid allocating.
return copy(data[:c.Size()], c.Cid.KeyString()), nil
}

func (c *Cid) Unmarshal(data []byte) (err error) {
Expand Down

0 comments on commit a1b6ce9

Please sign in to comment.