VictoriaMetrics/lib/slicesutil/slicesutil.go

11 lines
261 B
Go
Raw Normal View History

2024-05-11 02:52:36 +00:00
package slicesutil
// ExtendCapacity returns a with the capacity extended to len(a)+n if needed.
func ExtendCapacity[T any](a []T, n int) []T {
aLen := len(a)
if n := aLen + n - cap(a); n > 0 {
a = append(a[:cap(a)], make([]T, n)...)
}
return a[:aLen]
}