From 906b2fb5c12f169ab2e2d2bc3afe6bb297884215 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) --- message/pb/cid.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/message/pb/cid.go b/message/pb/cid.go index 59e32bb2..34862b3d 100644 --- a/message/pb/cid.go +++ b/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) {