mirror of
https://github.com/zsh-users/zsh-syntax-highlighting.git
synced 2025-04-17 11:35:32 +08:00
Perf: speed up highlighting of aliases
This commit is contained in:
parent
5150bef079
commit
200648df2b
@ -140,25 +140,15 @@ _zsh_highlight_main_calculate_fallback() {
|
|||||||
_zsh_highlight_main__type() {
|
_zsh_highlight_main__type() {
|
||||||
# Cache lookup
|
# Cache lookup
|
||||||
if (( $+_zsh_highlight_main__command_type_cache )); then
|
if (( $+_zsh_highlight_main__command_type_cache )); then
|
||||||
[[ -n ${REPLY::=$_zsh_highlight_main__command_type_cache[$1]} ]] && return
|
[[ -n ${REPLY::=$_zsh_highlight_main__command_type_cache[$1$2]} ]] && return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
integer -r aliases_allowed=${2-1}
|
integer -r aliases_allowed=$2
|
||||||
# We won't cache replies of anything that exists as an alias at all, to
|
|
||||||
# ensure the cached value is correct regardless of $aliases_allowed.
|
|
||||||
#
|
|
||||||
# ### We probably _should_ cache them in a cache that's keyed on the value of
|
|
||||||
# ### $aliases_allowed, on the assumption that aliases are the common case.
|
|
||||||
integer may_cache=1
|
|
||||||
|
|
||||||
local cmd
|
local cmd
|
||||||
|
|
||||||
# Main logic
|
# Main logic
|
||||||
unset REPLY
|
unset REPLY
|
||||||
if zmodload -e zsh/parameter; then
|
if zmodload -e zsh/parameter; then
|
||||||
if (( $+aliases[$1] )); then
|
|
||||||
may_cache=0
|
|
||||||
fi
|
|
||||||
if (( ${+galiases[$1]} )) && (( aliases_allowed )); then
|
if (( ${+galiases[$1]} )) && (( aliases_allowed )); then
|
||||||
REPLY='global alias'
|
REPLY='global alias'
|
||||||
elif (( $+aliases[$1] )) && (( aliases_allowed )); then
|
elif (( $+aliases[$1] )) && (( aliases_allowed )); then
|
||||||
@ -211,16 +201,14 @@ _zsh_highlight_main__type() {
|
|||||||
[[ $zsyh_user_options[pathdirs] == on ]] && setopt pathdirs
|
[[ $zsyh_user_options[pathdirs] == on ]] && setopt pathdirs
|
||||||
(( aliases_allowed )) || unalias -- "$1" 2>/dev/null
|
(( aliases_allowed )) || unalias -- "$1" 2>/dev/null
|
||||||
LC_ALL=C builtin type -w -- "$1" 2>/dev/null)##*: }:-none}"
|
LC_ALL=C builtin type -w -- "$1" 2>/dev/null)##*: }:-none}"
|
||||||
if [[ $REPLY == 'alias' ]]; then
|
if [[ $REPLY == 'hashed' && ( -n $cmd || $1 == */* ) ]]; then
|
||||||
may_cache=0
|
|
||||||
elif [[ $REPLY == 'hashed' && ( -n $cmd || $1 == */* ) ]]; then
|
|
||||||
REPLY=none
|
REPLY=none
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cache population
|
# Cache population
|
||||||
if (( may_cache && $+_zsh_highlight_main__command_type_cache )); then
|
if (( $+_zsh_highlight_main__command_type_cache )); then
|
||||||
_zsh_highlight_main__command_type_cache[$1]=$REPLY
|
_zsh_highlight_main__command_type_cache[$1$2]=$REPLY
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +216,7 @@ _zsh_highlight_main__type() {
|
|||||||
#
|
#
|
||||||
# Return 0 if runnable, 1 if not runnable.
|
# Return 0 if runnable, 1 if not runnable.
|
||||||
_zsh_highlight_main__is_runnable() {
|
_zsh_highlight_main__is_runnable() {
|
||||||
_zsh_highlight_main__type "$1"
|
_zsh_highlight_main__type "$1" 1
|
||||||
[[ $REPLY != none ]]
|
[[ $REPLY != none ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,12 +624,14 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
fi
|
fi
|
||||||
(( in_redirection++ )) # Stall this arg
|
(( in_redirection++ )) # Stall this arg
|
||||||
continue
|
continue
|
||||||
else
|
elif [[ $res == "none" ]]; then
|
||||||
_zsh_highlight_main_highlighter_expand_path $arg
|
_zsh_highlight_main_highlighter_expand_path $arg
|
||||||
|
if [[ $REPLY != $res ]]; then
|
||||||
_zsh_highlight_main__type "$REPLY" 0
|
_zsh_highlight_main__type "$REPLY" 0
|
||||||
res="$REPLY"
|
res="$REPLY"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Analyse the current word.
|
# Analyse the current word.
|
||||||
if _zsh_highlight_main__is_redirection $arg ; then
|
if _zsh_highlight_main__is_redirection $arg ; then
|
||||||
|
Loading…
Reference in New Issue
Block a user