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)
| 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. |
| 954 | func 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 |
| 966 | func EqualByteSlices(a, b [][]byte) bool { |