From d8026dad3c645a649fda3ff1e34066a3b94b723f Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 11 May 2024 04:52:36 +0200 Subject: [PATCH] wip --- lib/slicesutil/slicesutil.go | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/slicesutil/slicesutil.go diff --git a/lib/slicesutil/slicesutil.go b/lib/slicesutil/slicesutil.go new file mode 100644 index 000000000..4ce954224 --- /dev/null +++ b/lib/slicesutil/slicesutil.go @@ -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] +}