*highlight: Extension for HSMW: colorify two newline characters \n

This is a serious slow down for highlighting multi-line code not having
new lines replaced with '\n' – but such code can revert this patch, and
also should.

parse.zsh ./to-parse.zsh changes.out, after changes

Running time: 2.3695570000
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    1        2368,80  2368,80   99,99%   2222,89  2222,89   93,83%  -hsmw-highlight-process
 2)  754         124,15     0,16    5,24%    124,15     0,16    5,24%  -hsmw-highlight-main-type
 3)  395          12,22     0,03    0,52%     12,22     0,03    0,52%  -hsmw-highlight-check-path
 4)   22           5,99     0,27    0,25%      5,99     0,27    0,25%  -hsmw-highlight-string
 5)    6           2,60     0,43    0,11%      2,60     0,43    0,11%  -hsmw-highlight-dollar-string
 6)   46           0,95     0,02    0,04%      0,95     0,02    0,04%  -hsmw-highlight-stack-pop
 7)    1           0,15     0,15    0,01%      0,15     0,15    0,01%  -hsmw-highlight-fill-option-variables
 8)    1           0,02     0,02    0,00%      0,02     0,02    0,00%  -hsmw-highlight-init

Line-wise input is also affected, but the feature is too good to resign
of it.

parse.zsh -oo, after changes:

Running time: 1.5768150000
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)  350        1569,21     4,48   99,99%   1204,77     3,44   76,77%  -hsmw-highlight-process
 2) 2800         288,78     0,10   18,40%    288,78     0,10   18,40%  -hsmw-highlight-string
 3) 1750          41,03     0,02    2,61%     41,03     0,02    2,61%  -hsmw-highlight-check-path
 4) 1400          24,76     0,02    1,58%     24,76     0,02    1,58%  -hsmw-highlight-main-type
 5)  350           9,87     0,03    0,63%      9,87     0,03    0,63%  -hsmw-highlight-stack-pop
 6)    1           0,10     0,10    0,01%      0,10     0,10    0,01%  -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-31 14:13:07 +01:00
parent 12e631cd29
commit 939b96bdd5

View file

@ -58,6 +58,7 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
: ${HSMW_HIGHLIGHT_STYLES[assign]:=none}
: ${HSMW_HIGHLIGHT_STYLES[redirection]:=none}
: ${HSMW_HIGHLIGHT_STYLES[comment]:=fg=black,bold}
: ${HSMW_HIGHLIGHT_STYLES[newline]:=fg=black,bold} # '\n' strings
typeset -gA __HSMW_HIGHLIGHT_TOKENS_TYPES
@ -315,6 +316,7 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
if [[ "${proc_buf[offset+1]}" = $'\n' ]]; then
(( in_array_assignment )) && (( this_word = 2 )) || { (( this_word = 1 )); highlight_glob=1; }
in_redirection=0
reply+=("$(( start_pos - 1)) $end_pos ${HSMW_HIGHLIGHT_STYLES[newline]}")
proc_buf="${proc_buf[offset + $#arg + 1,len]}"
start_pos=$end_pos
continue