In the below code snippet, what exactly is the line after the if
block doing
slice = slice[0:l+len(data)]
?
func Append(slice, data []byte) []byte {
l := len(slice)
if l + len(data) > cap(slice) { // reallocate
// Allocate double what's needed, for future growth.
newSlice := make([]byte, (l+len(data))*2)
// The copy function is predeclared and works for any slice type.
copy(newSlice, slice)
slice = newSlice
}
slice = slice[0:l+len(data)] // <-- What is this doing ?
for i, c := range data {
slice[l+i] = c
}
return slice
}