Skip to content

Commit 214c1ef

Browse files
author
Dmitriy Matrenichev
committed
chore: set slice.Filter result slice cap to len
This change ensures that if we `append` to resulting slice in different places, we will not use the same underlying memory. Signed-off-by: Dmitriy Matrenichev <[email protected]>
1 parent 8e89b1e commit 214c1ef

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

slices/slices.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func Filter[S ~[]T, T any](slc S, fn func(T) bool) S {
6262
return nil
6363
}
6464

65-
return r
65+
return r[:len(r):len(r)]
6666
}
6767

6868
// FilterInPlace filters the slice in place.

0 commit comments

Comments
 (0)