Skip to content

Commit 38f6750

Browse files
renbouArtem Mikheev
and
Artem Mikheev
authored
optimization: preallocate result in FilterMap (#622)
Co-authored-by: Artem Mikheev <[email protected]>
1 parent d91b19f commit 38f6750

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

slice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func UniqMap[T any, R comparable](collection []T, iteratee func(item T, index in
5555
//
5656
// Play: https://go.dev/play/p/-AuYXfy7opz
5757
func FilterMap[T any, R any](collection []T, callback func(item T, index int) (R, bool)) []R {
58-
result := []R{}
58+
result := make([]R, 0, len(collection))
5959

6060
for i := range collection {
6161
if r, ok := callback(collection[i], i); ok {

0 commit comments

Comments
 (0)