diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-25 10:01:11 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-25 10:01:11 +0300 |
| commit | 146a362a59ffd64f45e436eb97035d03085692b4 (patch) | |
| tree | 16c0c468297db27d04cf55a75e64520c832c609e | |
| parent | f541136ae6cb3a3efa1bed3acafa3fee19b3a37e (diff) | |
style(repl): use map[string]struct{} for sets instead of map[string]bool
Idiomatic Go uses struct{} for zero-allocation sets. Two locations:
- GetCompletionTopics: seen deduplication map
- init(): seenCat category deduplication map
| -rw-r--r-- | internal/repl/help.go | 8 | ||||
| -rw-r--r-- | internal/repl/help_topics.go | 6 |
2 files changed, 7 insertions, 7 deletions
diff --git a/internal/repl/help.go b/internal/repl/help.go index 4c0691b..9796644 100644 --- a/internal/repl/help.go +++ b/internal/repl/help.go @@ -44,7 +44,7 @@ func GetAllTopics() []string { // GetCompletionTopics returns all help topics suitable for tab completion. // Includes operator names and aliases from all registered HelpTopic entries. func GetCompletionTopics() []string { - seen := make(map[string]bool) + seen := make(map[string]struct{}) var topics []string // Add all operator names (skip "help" itself — no need to complete help help) @@ -53,12 +53,12 @@ func GetCompletionTopics() []string { continue } topics = append(topics, op) - seen[op] = true + seen[op] = struct{}{} // Add aliases for _, a := range t.Aliases { - if !seen[a] { + if _, ok := seen[a]; !ok { topics = append(topics, a) - seen[a] = true + seen[a] = struct{}{} } } } diff --git a/internal/repl/help_topics.go b/internal/repl/help_topics.go index 34bb708..5c36140 100644 --- a/internal/repl/help_topics.go +++ b/internal/repl/help_topics.go @@ -503,14 +503,14 @@ var ( ) func init() { - seenCat := make(map[string]bool) + seenCat := make(map[string]struct{}) for i := range helpTopics { t := &helpTopics[i] for _, a := range t.Aliases { helpByAlias[a] = t } - if !seenCat[t.Category] { - seenCat[t.Category] = true + if _, ok := seenCat[t.Category]; !ok { + seenCat[t.Category] = struct{}{} categoryOrder = append(categoryOrder, t.Category) } helpByCat[t.Category] = append(helpByCat[t.Category], t.Operator) |
