This commit is contained in:
Aliaksandr Valialkin 2024-05-11 04:52:36 +02:00
parent 0c6ce34295
commit d8026dad3c
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -0,0 +1,10 @@
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]
}