Skip to content

Commit

Permalink
chore: set slice.Filter result slice cap to len
Browse files Browse the repository at this point in the history
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 <dmitry.matrenichev@siderolabs.com>
  • Loading branch information
DmitriyMV committed Dec 29, 2022
1 parent 8e89b1e commit 214c1ef
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion slices/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func Filter[S ~[]T, T any](slc S, fn func(T) bool) S {
return nil
}

return r
return r[:len(r):len(r)]
}

// FilterInPlace filters the slice in place.
Expand Down

0 comments on commit 214c1ef

Please sign in to comment.