From e16eae1a23ea4849429d0f69f711dd58d3e12638 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 18 Dec 2025 16:37:06 -0500 Subject: [PATCH] perf(ui): dialog: preallocate slice for filterable items in ModelsList --- internal/ui/dialog/models_list.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/ui/dialog/models_list.go b/internal/ui/dialog/models_list.go index fedc33a9a6ceddbdc77ceb051952924465eb54c1..c5707f65412c7fd2d5932377d07ab5b4d42467a3 100644 --- a/internal/ui/dialog/models_list.go +++ b/internal/ui/dialog/models_list.go @@ -26,6 +26,15 @@ func NewModelsList(sty *styles.Styles, groups ...ModelGroup) *ModelsList { return f } +// Len returns the number of model items across all groups. +func (f *ModelsList) Len() int { + n := 0 + for _, g := range f.groups { + n += len(g.Items) + } + return n +} + // SetGroups sets the model groups and updates the list items. func (f *ModelsList) SetGroups(groups ...ModelGroup) { f.groups = groups @@ -81,7 +90,7 @@ func (f *ModelsList) VisibleItems() []list.Item { return items } - filterableItems := []list.FilterableItem{} + filterableItems := make([]list.FilterableItem, 0, f.Len()) for _, g := range f.groups { for _, item := range g.Items { filterableItems = append(filterableItems, item)