From 95d7be54d9d4cdd73cd36e31e64b67965d517d68 Mon Sep 17 00:00:00 2001 From: naglis <827324+naglis@users.noreply.github.com> Date: Wed, 26 Jul 2023 00:06:33 +0300 Subject: [PATCH] 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. --- list/list.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/list/list.go b/list/list.go index c814db4..7b47879 100644 --- a/list/list.go +++ b/list/list.go @@ -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{}