Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: slow ssh host tab completion when many hosts
- X-seq: zsh-workers 49434
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Peter Palfrader <zsh-workers=zsh.org@xxxxxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: slow ssh host tab completion when many hosts
- Date: Wed, 22 Sep 2021 10:00:47 -0700
- Archived-at: <https://zsh.org/workers/49434>
- In-reply-to: <YUrpncsk4+J04KpI@sarek.noreply.org>
- List-id: <zsh-workers.zsh.org>
- References: <YUrpncsk4+J04KpI@sarek.noreply.org>
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