MCPcopy
hub / github.com/canopy-network/canopy / AppendWithBuffer

Function AppendWithBuffer

lib/util.go:954–963  ·  view source on GitHub ↗

AppendWithBuffer() appends a and b into a fresh []byte using a buffer to reduce allocations. The result is safe to retain and use independently of a/b/buffer.

(buf *[]byte, a, b []byte)

Source from the content-addressed store, hash-verified

952// AppendWithBuffer() appends a and b into a fresh []byte using a buffer to reduce allocations.
953// The result is safe to retain and use independently of a/b/buffer.
954func AppendWithBuffer(buf *[]byte, a, b []byte) []byte {
955 totalLen := len(a) + len(b)
956 if cap(*buf) < totalLen {
957 *buf = make([]byte, totalLen)
958 }
959 *buf = (*buf)[:totalLen]
960 copy(*buf, a)
961 copy((*buf)[len(a):], b)
962 return *buf
963}
964
965// EqualByteSlices() performs equality check on two byte slices
966func EqualByteSlices(a, b [][]byte) bool {

Callers 1

GetMethod · 0.92

Calls 1

copyFunction · 0.50

Tested by

no test coverage detected