Perf: use -x $1 instead of -n $1(#q-.*N)

This commit is contained in:
Roman Perepelitsa 2020-09-12 10:01:01 +02:00
parent 8a17a5d1c0
commit 5150bef079

View File

@ -171,7 +171,7 @@ _zsh_highlight_main__type() {
REPLY=function REPLY=function
elif (( $+builtins[$1] )); then elif (( $+builtins[$1] )); then
REPLY=builtin REPLY=builtin
elif [[ $1 != */* && -x ${cmd::=${commands[$1]-}} ]]; then elif [[ $1 != */* && -x ${cmd::=${commands[$1]-}} && -f $cmd ]]; then
# There is one case where the following logic incorrectly sets REPLY=command # There is one case where the following logic incorrectly sets REPLY=command
# instead of REPLY=hashed. # instead of REPLY=hashed.
# #
@ -184,22 +184,20 @@ _zsh_highlight_main__type() {
else else
REPLY=hashed REPLY=hashed
fi fi
elif [[ $1 == */* && -x $1 && -f $1 ]]; then
REPLY=command
# ZSH_VERSION >= 5.1 allows the use of #q. ZSH_VERSION <= 5.8 allows skipping # ZSH_VERSION >= 5.1 allows the use of #q. ZSH_VERSION <= 5.8 allows skipping
# 'type -w' calls that are necessary for forward compatibility (5.8 is the latest # 'type -w' calls that are necessary for forward compatibility (5.8 is the latest
# zsh release at the time of writing). # zsh release at the time of writing).
elif [[ $ZSH_VERSION == 5.<1-8>(|.*) ]]; then elif [[ $ZSH_VERSION == 5.<1-8>(|.*) ]]; then
if [[ $1 == */* ]]; then REPLY=none
# [[ -n $1(#q-.*N) ]] is a faster version of [[ -f $1 && -x $1 ]]. if [[ $1 != */* || ($1 != /* && $zsyh_user_options[pathdirs] == on) ]]; then
if [[ -n $1(#q-.*N) || for cmd in ${^path}/$1(#q-.*N); do
$1 != /* && $zsyh_user_options[pathdirs] == on && -n ${^path}/$1(#q-.*N) ]]; then if [[ -x $cmd ]]; then
REPLY=command REPLY=command
else break
REPLY=none fi
fi done
elif [[ -n ${^path}/$1(#q-.*N) ]]; then
REPLY=command
else
REPLY=none
fi fi
fi fi
fi fi