github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/slicehelper/slicehelper.go (about) 1 package slicehelper 2 3 // Extend extends the input slice by n elements. head is the full extended 4 // slice, while tail is the appended part. If the original slice has sufficient 5 // capacity no allocation is performed. 6 func Extend[S ~[]E, E any](in S, n int) (head, tail S) { 7 if total := len(in) + n; cap(in) >= total { 8 head = in[:total] 9 } else { 10 head = make(S, total) 11 copy(head, in) 12 } 13 tail = head[len(in):] 14 return 15 }