From a1b6ce98d1ce87bfd127dc8b11726166665e5a27 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 13 Apr 2020 07:23:51 -0700 Subject: [PATCH] fix: avoid allocating cids (#348) This commit was moved from ipfs/go-bitswap@906b2fb5c12f169ab2e2d2bc3afe6bb297884215 --- bitswap/message/pb/cid.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bitswap/message/pb/cid.go b/bitswap/message/pb/cid.go index 59e32bb27..34862b3d4 100644 --- a/bitswap/message/pb/cid.go +++ b/bitswap/message/pb/cid.go @@ -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) {