From 60e701271fb8353e566c3f7fc15ad670a96ed8e7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 21 May 2025 22:34:01 +0530 Subject: [PATCH] Use a cache for icons --- kittens/choose_files/main.go | 2 +- kittens/choose_files/results.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/kittens/choose_files/main.go b/kittens/choose_files/main.go index f09479406..5acba7fd3 100644 --- a/kittens/choose_files/main.go +++ b/kittens/choose_files/main.go @@ -53,7 +53,7 @@ func (h *Handler) draw_screen() (err error) { h.draw_search_bar(0) }() y := SEARCH_BAR_HEIGHT - y += h.draw_results(y, 4, matches, in_progress) + y += h.draw_results(y, 2, matches, in_progress) return } diff --git a/kittens/choose_files/results.go b/kittens/choose_files/results.go index cf61cb1da..0a44234f8 100644 --- a/kittens/choose_files/results.go +++ b/kittens/choose_files/results.go @@ -93,11 +93,20 @@ func (h *Handler) render_match_with_positions(text string, stop_at int, position } } +var icon_cache map[string]string + func icon_for(path string, x os.DirEntry) string { + if icon_cache == nil { + icon_cache = make(map[string]string, 512) + } + if ans := icon_cache[path]; ans != "" { + return ans + } ans := icons.IconForFileWithMode(path, x.Type(), true) if wcswidth.Stringwidth(ans) == 1 { ans += " " } + icon_cache[path] = ans return ans }