Skip to content

Commit

Permalink
refactor(list): reduce allocations in filterItems (#396)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
naglis committed Jul 25, 2023
1 parent 0bdcc62 commit 95d7be5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,11 +1218,11 @@ func filterItems(m Model) tea.Cmd {
return FilterMatchesMsg(m.itemsAsFilterItems()) // return nothing
}

targets := []string{}
items := m.items
targets := make([]string, len(items))

for _, t := range items {
targets = append(targets, t.FilterValue())
for i, t := range items {
targets[i] = t.FilterValue()
}

filterMatches := []filteredItem{}
Expand Down

0 comments on commit 95d7be5

Please sign in to comment.