panic("cannot be negative")
}
if n -= cap(s) - len(s); n > 0 {
+ // This expression allocates only once (see test).
s = append(s[:cap(s)], make([]E, n)...)[:len(s)]
}
return s
panic("len out of range")
}
}
+ // Use Grow, not make, to round up to the size class:
+ // the extra space is otherwise unused and helps
+ // callers that append a few elements to the result.
newslice := Grow[S](nil, size)
for _, s := range slices {
newslice = append(newslice, s...)