From 18cd426cb2f5adcce45dd9357f9c3e958117b085 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Tue, 25 Oct 2016 18:06:45 +0200 Subject: [PATCH] *highlight: Huge optimization: Don't redefine variables at each loop parse.zsh -oo, after changes: Running time: 1.7135350000 num calls time self name ----------------------------------------------------------------------------------- 1) 350 1706,03 4,87 99,99% 1230,37 3,52 72,11% -hsmw-highlight-process 2) 2800 338,39 0,12 19,83% 338,39 0,12 19,83% -hsmw-highlight-string 3) 2450 81,56 0,03 4,78% 81,56 0,03 4,78% -hsmw-highlight-check-path 4) 1400 38,43 0,03 2,25% 38,43 0,03 2,25% -hsmw-highlight-main-type 5) 350 9,85 0,03 0,58% 9,85 0,03 0,58% -hsmw-highlight-stack-pop 6) 350 7,44 0,02 0,44% 7,44 0,02 0,44% -hsmw-highlight-path-separators 7) 1 0,12 0,12 0,01% 0,12 0,12 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hsmw-highlight b/hsmw-highlight index f49fdce..00c4d98 100644 --- a/hsmw-highlight +++ b/hsmw-highlight @@ -280,10 +280,10 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=( # integer BIT_start=1 BIT_regular=2 BIT_sudo_opt=4 BIT_sudo_arg=8 BIT_always=16 - integer this_word=BIT_start next_word=0 already_added + integer this_word=BIT_start next_word=0 already_added offset # Processing buffer - local proc_buf="$buf" + local proc_buf="$buf" needle for arg in ${interactive_comments-${(z)buf}} \ ${interactive_comments+${(zZ+c+)buf}}; do # Initialize $next_word to its default value? @@ -318,14 +318,14 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=( # token altogether, so 'echo foo\necho bar' (two commands) becomes # indistinguishable from 'echo foo echo bar' (one command with three # words for arguments). - local needle=$'[;\n]' - integer offset=$(( ${proc_buf[(i)$needle]} - 1 )) + needle=$'[;\n]' + offset=$(( ${proc_buf[(i)$needle]} - 1 )) (( start_pos += offset )) (( end_pos = start_pos + $#arg )) arg_type=3 else - integer offset=0 + offset=0 if [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\[[:space:]])##)* ]]; then # The first, outer parenthesis offset="${mend[1]}"