Files
traces/pkg/util/slices.go
Ruslan MikhailovandGitHub e445568698 [bugfix] TraceQL Metrics: panic in compare (#5519)
Buffer and engine metrics were sharing ownership to one array.
Fix is to copy the array.
2025-08-15 10:04:47 +02:00

13 lines
372 B
Go

package util
// Clone returns a copy of the slice.
// The elements are copied using assignment, so this is a shallow clone.
// The difference with slices.Clone is that the result will not have additional unused capacity.
func Clone[S ~[]E, E any](s S) S {
// Preserve nilness in case it matters.
if s == nil {
return nil
}
return append(make(S, 0, len(s)), s...)
}