From 610144c56f90582d7f0bb3595730062ab2d6b332 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Wed, 26 Oct 2016 11:05:27 +0200 Subject: [PATCH] *highlight: Optimization: declare *-string vars outside, once parse.zsh -oo, after changes: Running time: 1.5839050000 num calls time self name ----------------------------------------------------------------------------------- 1) 350 1576,36 4,50 99,99% 1177,23 3,36 74,68% -hsmw-highlight-process 2) 2800 292,16 0,10 18,53% 292,16 0,10 18,53% -hsmw-highlight-string 3) 2450 72,24 0,03 4,58% 72,24 0,03 4,58% -hsmw-highlight-check-path 4) 1400 24,98 0,02 1,58% 24,98 0,02 1,58% -hsmw-highlight-main-type 5) 350 9,74 0,03 0,62% 9,74 0,03 0,62% -hsmw-highlight-stack-pop 6) 1 0,07 0,07 0,00% 0,07 0,07 0,00% -hsmw-highlight-fill-option-variables 7) 1 0,01 0,01 0,00% 0,01 0,01 0,00% -hsmw-highlight-init --- hsmw-highlight | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hsmw-highlight b/hsmw-highlight index a4c86b3..ca06b55 100644 --- a/hsmw-highlight +++ b/hsmw-highlight @@ -222,9 +222,11 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=( # Variable declarations and initializations # in_array_assignment true between 'a=(' and the matching ')' # braces_stack: "R" for round, "Q" for square, "Y" for curly - local start_pos=0 end_pos highlight_glob=1 arg style in_array_assignment=0 MATCH expanded_path braces_stack buf=$1 + # mybuf is used in sub-functions + local start_pos=0 end_pos highlight_glob=1 arg style in_array_assignment=0 MATCH expanded_path braces_stack buf=$1 mybuf # arg_type can be 0, 1, 2 or 3, i.e. precommand, control flow, command separator - integer arg_type=0 MBEGIN MEND in_redirection len=${#buf} + # idx and end_idx are used in sub-functions + integer arg_type=0 MBEGIN MEND in_redirection len=${#buf} already_added offset idx end_idx local -a match mbegin mend # State machine @@ -265,7 +267,7 @@ __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 offset + integer this_word=BIT_start next_word=0 # Processing buffer local proc_buf=$buf needle @@ -635,8 +637,8 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=( { local -a match mbegin mend - local mybuf=$arg - integer idx=start_pos end_idx + mybuf=$arg + idx=start_pos while [[ $mybuf = (#b)[^\$\\]#((\$[a-zA-Z0-9_]##(\[[^\]]#\])(#c0,1))|(\$[{](\([a-zA-Z0@%#]##\))(#c0,1)[a-zA-Z0-9_]##(\[[^\]]#\])(#c0,1)[}])|[\\][\'\"\$]|[\\](*))(*) ]]; do [[ -n ${match[7]} ]] && {