From 760d1b7c5847c1c9782271966fe8a36bbf027818 Mon Sep 17 00:00:00 2001 From: mickychang9 Date: Mon, 29 Sep 2025 17:11:19 +0800 Subject: [PATCH] refactor: use maps.Copy and maps.Clone (#4518) Signed-off-by: mickychang9 --- src/core.go | 6 ++---- src/options.go | 5 ++--- src/terminal.go | 6 ++---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/core.go b/src/core.go index da7da137..a4fbfe04 100644 --- a/src/core.go +++ b/src/core.go @@ -2,6 +2,7 @@ package fzf import ( + "maps" "os" "sync" "time" @@ -225,10 +226,7 @@ func Run(opts *Options) (int, error) { } patternBuilder := func(runes []rune) *Pattern { denyMutex.Lock() - denylistCopy := make(map[int32]struct{}) - for k, v := range denylist { - denylistCopy[k] = v - } + denylistCopy := maps.Clone(denylist) denyMutex.Unlock() return BuildPattern(cache, patternCache, opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward, withPos, diff --git a/src/options.go b/src/options.go index 27ec3d78..f3ba8518 100644 --- a/src/options.go +++ b/src/options.go @@ -3,6 +3,7 @@ package fzf import ( "errors" "fmt" + "maps" "os" "regexp" "strconv" @@ -2603,9 +2604,7 @@ func parseOptions(index *int, opts *Options, allArgs []string) error { if err != nil { return err } - for k, v := range chords { - opts.Expect[k] = v - } + maps.Copy(opts.Expect, chords) case "--no-expect": opts.Expect = make(map[tui.Event]string) case "--enabled", "--no-phony": diff --git a/src/terminal.go b/src/terminal.go index 4f78ab2e..d18a0ba7 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "io" + "maps" "math" "net" "os" @@ -950,10 +951,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor wordRubout = fmt.Sprintf("%s[^%s]", sep, sep) wordNext = fmt.Sprintf("[^%s]%s|(.$)", sep, sep) } - keymapCopy := make(map[tui.Event][]*action) - for key, action := range opts.Keymap { - keymapCopy[key] = action - } + keymapCopy := maps.Clone(opts.Keymap) t := Terminal{ initDelay: delay,