From 5febb0340f9ec2b3c5c88475f322ff57bc8e9fd7 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Tue, 25 Oct 2016 18:49:53 +0200 Subject: [PATCH] *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 --- hsmw-highlight | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/hsmw-highlight b/hsmw-highlight index 946677d..699ab2f 100644 --- a/hsmw-highlight +++ b/hsmw-highlight @@ -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.