| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
// Package internal provides internal functionality for the metric package. |
| 5 |
package internal // import "go.opentelemetry.io/otel/sdk/metric/internal" |
| 6 |
|
| 7 |
// ReuseSlice returns a zeroed view of slice if its capacity is greater than or |
| 8 |
// equal to n. Otherwise, it returns a new []T with capacity equal to n. |
| 9 |
func ReuseSlice[T any](slice []T, n int) []T { |
| 10 |
if cap(slice) >= n { |
| 11 |
return slice[:n] |
| 12 |
} |
| 13 |
return make([]T, n) |
| 14 |
} |