1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-05 11:01:13 +02:00

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.
This commit is contained in:
Peter Palfrader 2021-09-22 10:25:08 +02:00 committed by Oliver Kiddle
parent f2b6650b43
commit c4b19f7fc4
2 changed files with 8 additions and 4 deletions

View file

@ -1,5 +1,8 @@
2021-10-26 Oliver Kiddle <opk@zsh.org> 2021-10-26 Oliver Kiddle <opk@zsh.org>
* Peter Palfrader: 49431 (tweaked, c.f. Bart: 49434):
Completion/Unix/Type/_ssh_hosts: Faster ~/.ssh/config processing
* Marlon: 49521: Doc/Zsh/compwid.yo, Test/Y02compmatch.ztst: * Marlon: 49521: Doc/Zsh/compwid.yo, Test/Y02compmatch.ztst:
Define correct behavior of || completion matchers Define correct behavior of || completion matchers

View file

@ -20,8 +20,9 @@ if [[ -r $config ]]; then
local key line host local key line host
local -a lines=("${(@f)$(<"$config")}") 2>/dev/null local -a lines=("${(@f)$(<"$config")}") 2>/dev/null
local -a match_args local -a match_args
while (($#lines)); do local idx=1
IFS=$'=\t ' read -r key line <<<"${lines[1]}" while (( idx <= $#lines )); do
IFS=$'=\t ' read -r key line <<<"${lines[idx]}"
if [[ "$key" == ((#i)match) ]]; then if [[ "$key" == ((#i)match) ]]; then
match_args=(${(z)line}) match_args=(${(z)line})
while [[ $#match_args -ge 2 ]]; do while [[ $#match_args -ge 2 ]]; do
@ -35,7 +36,7 @@ if [[ -r $config ]]; then
fi fi
case "$key" in case "$key" in
((#i)include) ((#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)) ((#i)host(|name))
for host in ${(z)line}; do for host in ${(z)line}; do
case $host in case $host in
@ -43,7 +44,7 @@ if [[ -r $config ]]; then
(*) config_hosts+=("$host") ;; (*) config_hosts+=("$host") ;;
esac esac
done ;& done ;&
(*) shift lines;; (*) (( ++idx ));;
esac esac
done done
if (( ${#config_hosts} )); then if (( ${#config_hosts} )); then