Skip to content

Commit

Permalink
add cid.Append to efficiently extract the binary representation
Browse files Browse the repository at this point in the history
This skips an allocation when appending strings to bytes.
  • Loading branch information
Jorropo committed Feb 17, 2024
1 parent 4339493 commit 468cca0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cid.go
Expand Up @@ -607,6 +607,11 @@ func (c CidOf[S]) Prefix() Prefix {
}
}

// Append appends the cid to some slice of bytes.
func (c CidOf[S]) Append(in []byte) []byte {
return append(in, c.storage...)

Check warning on line 612 in cid.go

View check run for this annotation

Codecov / codecov/patch

cid.go#L611-L612

Added lines #L611 - L612 were not covered by tests
}

// Prefix represents all the metadata of a Cid,
// that is, the Version, the Codec, the Multihash type
// and the Multihash length. It does not contains
Expand Down

0 comments on commit 468cca0

Please sign in to comment.