From 5b11656e45a6a6579298a3b28c71f456ff196ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 18 May 2022 03:57:08 +0300 Subject: [PATCH] perf(bash-v2): read directly to COMPREPLY on descriptionless short circuit (#1700) Not that it'd really matter that much performancewise given the level we are at for this case, but this change makes the short circuit roughly twice as fast on my box as it was for the 1000 rounds done in marckhouzam/cobra-completion-testing. Perhaps more importantly, this makes the code arguably slightly cleaner. --- bash_completionsV2.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bash_completionsV2.go b/bash_completionsV2.go index 97202f1b..e61e27c9 100644 --- a/bash_completionsV2.go +++ b/bash_completionsV2.go @@ -178,9 +178,7 @@ __%[1]s_handle_standard_completion_case() { # Short circuit to optimize if we don't have descriptions if [[ $out != *$tab* ]]; then - while IFS='' read -r comp; do - COMPREPLY+=("$comp") - done < <(IFS=$'\n' compgen -W "$out" -- "$cur") + IFS=$'\n' read -ra COMPREPLY -d '' < <(IFS=$'\n' compgen -W "$out" -- "$cur") return 0 fi