-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
}
bravoecho, Splizard, crossworth, jfesler, exapsy and 15 moreMerovius, hherman1, Dynom, fdonzello, as and 3 moreainar-g