*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
This commit is contained in:
Sebastian Gniazdowski 2016-10-26 11:05:27 +02:00
parent 2c77ee78f2
commit 610144c56f

View file

@ -222,9 +222,11 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
# Variable declarations and initializations # Variable declarations and initializations
# in_array_assignment true between 'a=(' and the matching ')' # in_array_assignment true between 'a=(' and the matching ')'
# braces_stack: "R" for round, "Q" for square, "Y" for curly # 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 # 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 local -a match mbegin mend
# State machine # 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 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 # Processing buffer
local proc_buf=$buf needle local proc_buf=$buf needle
@ -635,8 +637,8 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
{ {
local -a match mbegin mend local -a match mbegin mend
local mybuf=$arg mybuf=$arg
integer idx=start_pos end_idx idx=start_pos
while [[ $mybuf = (#b)[^\$\\]#((\$[a-zA-Z0-9_]##(\[[^\]]#\])(#c0,1))|(\$[{](\([a-zA-Z0@%#]##\))(#c0,1)[a-zA-Z0-9_]##(\[[^\]]#\])(#c0,1)[}])|[\\][\'\"\$]|[\\](*))(*) ]]; do while [[ $mybuf = (#b)[^\$\\]#((\$[a-zA-Z0-9_]##(\[[^\]]#\])(#c0,1))|(\$[{](\([a-zA-Z0@%#]##\))(#c0,1)[a-zA-Z0-9_]##(\[[^\]]#\])(#c0,1)[}])|[\\][\'\"\$]|[\\](*))(*) ]]; do
[[ -n ${match[7]} ]] && { [[ -n ${match[7]} ]] && {