Closed
Description
Working directly with []byte
is very common and needing to copy it comes up fairly often. A Clone
helper would be nice to have.
What did you expect to see?
dup := bytes.Clone(data)
What did you see instead?
dup := make([]byte, len(data))
copy(dup, data)
Implementation
package bytes
// Clone returns a copy of b
func Clone(b []byte) []byte {
b2 := make([]byte, len(b))
copy(b2, b)
return b2
}