【发布时间】:2017-07-11 09:42:28
【问题描述】:
在下面的代码 sn-p 中,if 块后面的行到底在做什么
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
}
【问题讨论】:
标签: go