From 3f1c31c21e43ba597e6533ae1208d8cc9fe735ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 10 May 2023 00:03:16 +0300 Subject: [PATCH] Avoid redundant active help enablement evaluations The enablement state is not to be changed during completion output, so evaluate it only once. --- completions.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/completions.go b/completions.go index f9401888..95e1dc1f 100644 --- a/completions.go +++ b/completions.go @@ -217,13 +217,12 @@ func (c *Command) initCompleteCmd(args []string) { } noDescriptions := (cmd.CalledAs() == ShellCompNoDescRequestCmd) + noActiveHelp := GetActiveHelpConfig(finalCmd) == activeHelpGlobalDisable out := finalCmd.OutOrStdout() for _, comp := range completions { - if GetActiveHelpConfig(finalCmd) == activeHelpGlobalDisable { - // Remove all activeHelp entries in this case - if strings.HasPrefix(comp, activeHelpMarker) { - continue - } + if noActiveHelp && strings.HasPrefix(comp, activeHelpMarker) { + // Remove all activeHelp entries if it's disabled. + continue } if noDescriptions { // Remove any description that may be included following a tab character.