*highlight: Optimization: *-type to not guard cache with ifs; compress

parse.zsh -oo, after changes:

Running time: 1.6934050000
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)  350        1685,89     4,82   99,99%   1225,79     3,50   72,70%  -hsmw-highlight-process
 2) 2800         336,76     0,12   19,97%    336,76     0,12   19,97%  -hsmw-highlight-string
 3) 2450          80,37     0,03    4,77%     80,37     0,03    4,77%  -hsmw-highlight-check-path
 4) 1400          25,65     0,02    1,52%     25,65     0,02    1,52%  -hsmw-highlight-main-type
 5)  350           9,80     0,03    0,58%      9,80     0,03    0,58%  -hsmw-highlight-stack-pop
 6)  350           7,52     0,02    0,45%      7,52     0,02    0,45%  -hsmw-highlight-path-separators
 7)    1           0,09     0,09    0,01%      0,09     0,09    0,01%  -hsmw-highlight-fill-option-variables
 8)    1           0,01     0,01    0,00%      0,01     0,01    0,00%  -hsmw-highlight-init
This commit is contained in:
Sebastian Gniazdowski 2016-10-25 18:49:53 +02:00
parent 069cd53650
commit 5febb0340f

View file

@ -119,13 +119,9 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
#
# The result will be stored in REPLY.
-hsmw-highlight-main-type() {
if (( $+__hsmw_highlight_main__command_type_cache )); then
REPLY=$__hsmw_highlight_main__command_type_cache[(e)$1]
if [[ -n "$REPLY" ]]; then
return
fi
fi
unset REPLY
REPLY=$__hsmw_highlight_main__command_type_cache[(e)$1]
[[ -n "$REPLY" ]] && return
if zmodload -e zsh/parameter; then
if (( $+commands[(e)$1] )); then
REPLY=command
@ -150,12 +146,10 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
REPLY=none
fi
fi
if (( $+REPLY == 0 )); then
REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)#*: }"
fi
if (( $+__hsmw_highlight_main__command_type_cache )); then
__hsmw_highlight_main__command_type_cache[(e)$1]=$REPLY
fi
[[ -z "$REPLY" ]] && REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)#*: }"
__hsmw_highlight_main__command_type_cache[(e)$1]=$REPLY
}
# Resolve alias.