Skip to content

Commit 95d7be5

Browse files
authored
refactor(list): reduce allocations in filterItems (#396)
As the number of items in `targets` is known, use `make` with the expected size instead of appending, which requires more allocations as the `targets` slice grows.
1 parent 0bdcc62 commit 95d7be5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

list/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,11 +1218,11 @@ func filterItems(m Model) tea.Cmd {
12181218
return FilterMatchesMsg(m.itemsAsFilterItems()) // return nothing
12191219
}
12201220

1221-
targets := []string{}
12221221
items := m.items
1222+
targets := make([]string, len(items))
12231223

1224-
for _, t := range items {
1225-
targets = append(targets, t.FilterValue())
1224+
for i, t := range items {
1225+
targets[i] = t.FilterValue()
12261226
}
12271227

12281228
filterMatches := []filteredItem{}

0 commit comments

Comments
 (0)