// grow grows the slice s so that it can hold extra more values, allocating
// more capacity if needed. It also returns the old and new slice lengths.
func grow(s Value, extra int) (Value, int, int) {
i0 := s.Len()
i1 := i0 + extra
ifi1 < i0 {
panic("reflect.Append: slice overflow")
}
m := s.Cap()
ifi1 <= m {
returns.Slice(0, i1), i0, i1
}
ifm == 0 {
m = extra
} else{
form < i1 {
ifi0 < 1024 {
m += m
} else{
m += m / 4
}
}
}
t := MakeSlice(s.Type(), i1, m)
Copy(t, s)
returnt, i0, i1
}
// Append appends the values x to a slice s and returns the resulting slice.
// As in Go, each x's value must be assignable to the slice's element type.
func Append(s Value, x ...Value) Value {
s.mustBe(Slice)
s, i0, i1 := grow(s, len(x))
fori, j := i0, 0; i < i1; i, j = i+1, j+1 {
s.Index(i).Set(x[j])
}
returns
}