diff options
author | Peter Palfrader <peter@palfrader.org> | 2021-09-22 10:25:08 +0200 |
---|---|---|
committer | Oliver Kiddle <opk@zsh.org> | 2021-10-26 21:56:23 +0200 |
commit | c4b19f7fc4707321801973b259387c4e59de90cd (patch) | |
tree | 8155f9cc8034e6bb1c0154e086ce3942cbcaa495 /Completion/Unix | |
parent | f2b6650b43688eb38ffe88b3ed3c819b48fa141c (diff) | |
download | zsh-c4b19f7fc4707321801973b259387c4e59de90cd.tar.gz zsh-c4b19f7fc4707321801973b259387c4e59de90cd.tar.xz zsh-c4b19f7fc4707321801973b259387c4e59de90cd.zip |
49431 (tweaked, c.f. Bart: 49434): Faster ~/.ssh/config processing
When iterating over the ssh config file, iterate over the array linearly instead of always processing the first and then removing it from the list. This speeds up processing significantly.
Diffstat (limited to 'Completion/Unix')
-rw-r--r-- | Completion/Unix/Type/_ssh_hosts | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Completion/Unix/Type/_ssh_hosts b/Completion/Unix/Type/_ssh_hosts index bd5366425..a4a08ad91 100644 --- a/Completion/Unix/Type/_ssh_hosts +++ b/Completion/Unix/Type/_ssh_hosts @@ -20,8 +20,9 @@ if [[ -r $config ]]; then local key line host local -a lines=("${(@f)$(<"$config")}") 2>/dev/null local -a match_args - while (($#lines)); do - IFS=$'=\t ' read -r key line <<<"${lines[1]}" + local idx=1 + while (( idx <= $#lines )); do + IFS=$'=\t ' read -r key line <<<"${lines[idx]}" if [[ "$key" == ((#i)match) ]]; then match_args=(${(z)line}) while [[ $#match_args -ge 2 ]]; do @@ -35,7 +36,7 @@ if [[ -r $config ]]; then fi case "$key" in ((#i)include) - lines[1]=("${(@f)$(cd $HOME/.ssh; cat ${(z)~line})}") 2>/dev/null;; + lines[idx]=("${(@f)$(cd $HOME/.ssh; cat ${(z)~line})}") 2>/dev/null;; ((#i)host(|name)) for host in ${(z)line}; do case $host in @@ -43,7 +44,7 @@ if [[ -r $config ]]; then (*) config_hosts+=("$host") ;; esac done ;& - (*) shift lines;; + (*) (( ++idx ));; esac done if (( ${#config_hosts} )); then |