From: Bart Schaefer <schaefer@brasslantern.com>
To: Peter Palfrader <zsh-workers=zsh.org@lists.palfrader.org>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: slow ssh host tab completion when many hosts
Date: Wed, 22 Sep 2021 10:00:47 -0700 [thread overview]
Message-ID: <CAH+w=7ZOe6CV44nnL_PD8q+u3eZ9kVLQi76bEY_-9_jRvvSvMA@mail.gmail.com> (raw)
In-Reply-To: <YUrpncsk4+J04KpI@sarek.noreply.org>
On Wed, Sep 22, 2021 at 1:31 AM Peter Palfrader
<zsh-workers=zsh.org@lists.palfrader.org> 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++))
prev parent reply other threads:[~2021-09-22 17:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-22 8:30 Peter Palfrader
2021-09-22 17:00 ` Bart Schaefer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7ZOe6CV44nnL_PD8q+u3eZ9kVLQi76bEY_-9_jRvvSvMA@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=zsh-workers=zsh.org@lists.palfrader.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).