Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: slow ssh host tab completion when many hosts



On Wed, Sep 22, 2021 at 1:31 AM Peter Palfrader
<zsh-workers=zsh.org@xxxxxxxxxxxxxxxxxxx> wrote:
>
> I suspect, that one of the issues is in _ssh_hosts where it always pops
> the first element of an array.  At a guess this causes quadratic
> runtime behaviour.

"shift" would imply a copy of the tail of the array, yes.

> The following patch improves the behaviour significantly (to about
> 2secs):

This looks OK, but it can be improved a bit further.  Firstly,
anywhere you are writing lines[$idx] you can just use lines[idx]
because everything inside the square brackets of an array dereference
is treated as a math expression.  Secondly:

> @@ -43,7 +44,7 @@ if [[ -r $config ]]; then
>         (*) config_hosts+=("$host") ;;
>         esac
>        done ;&
> -    (*) shift lines;;
> +    (*) idx=$((idx + 1));;
>      esac
>    done
>    if (( ${#config_hosts} )); then

Instead of the assignment idx=$((idx + 1))
you can use the statement ((idx++))




Messages sorted by: Reverse Date, Date, Thread, Author