*highlight: Fully optimal *-string, no / substitution and (S) flag

parse.zsh -oo, before changes:

Running time: 2.9235860000
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)  350        2916,15     8,33  100,00%   1727,84     4,94   59,25%  -hsmw-highlight-process
 2) 2800         764,12     0,27   26,20%    764,12     0,27   26,20%  -hsmw-highlight-string
 3) 2450         196,31     0,08    6,73%    134,73     0,05    4,62%  -hsmw-highlight-check-path
 4) 3850          95,16     0,02    3,26%     95,16     0,02    3,26%  -hsmw-highlight-expand-path
 5) 1400          67,34     0,05    2,31%     67,34     0,05    2,31%  (anon)
 6) 8400          56,32     0,01    1,93%     56,32     0,01    1,93%  -hsmw-highlight-is-redirection
 7) 1400          41,19     0,03    1,41%     41,19     0,03    1,41%  -hsmw-highlight-main-type
 8)  700          11,24     0,02    0,39%     11,24     0,02    0,39%  -hsmw-highlight-check-assign

parse.zsh -oo, after changes:

Running time: 2.5433330000
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)  350        2535,74     7,24  100,00%   1730,74     4,94   68,25%  -hsmw-highlight-process
 2) 2800         385,15     0,14   15,19%    385,15     0,14   15,19%  -hsmw-highlight-string
 3) 2450         193,50     0,08    7,63%    132,71     0,05    5,23%  -hsmw-highlight-check-path
 4) 3850          94,23     0,02    3,72%     94,23     0,02    3,72%  -hsmw-highlight-expand-path
 5) 1400          67,68     0,05    2,67%     67,68     0,05    2,67%  (anon)
 6) 8400          55,01     0,01    2,17%     55,01     0,01    2,17%  -hsmw-highlight-is-redirection
 7) 1400          41,00     0,03    1,62%     41,00     0,03    1,62%  -hsmw-highlight-main-type
 8)  700          11,01     0,02    0,43%     11,01     0,02    0,43%  -hsmw-highlight-check-assign

764.12 - 385.15 = 378.97
2916.15 - 2535.74 = 380,41
380 / 2916.0 = 0.13
This commit is contained in:
Sebastian Gniazdowski 2016-10-16 13:24:50 +02:00
parent 26a66c0bcc
commit 08419957ee

View file

@ -695,18 +695,20 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
local mybuf="$arg"
integer idx=start_pos end_idx
while (( 1 )); do
match=()
mybuf="${(S)mybuf/(#b)(*)((((\$[[:alnum:]_]##)[^[:alnum:]]|\$[[:alnum:]_]##(#e))(\[[^[:space:]]#\])(#c0,1))|(\$\{(\([a-zA-Z0@%#]##\))(#c0,1)[[:alnum:]_]##(\[[^[:space:]]#\])(#c0,1)\})|[\\][\'\"\$])/}"
while [[ "$mybuf" = (#b)([^\$\\]#)((\$[[:alnum:]_]##(\[[^[:space:]]#\])(#c0,1))|(\$[{](\([a-zA-Z0@%#]##\))(#c0,1)[[:alnum:]_]##(\[[^[:space:]]#\])(#c0,1)[}])|[\\][\'\"\$]|[\\](*))(*) ]]; do
[[ -n "${match[8]}" ]] && {
idx+="${#match[1]}"+1
mybuf="${match[8]}"
} || {
idx+="${#match[1]}"
end_idx=idx+"${#match[2]}"
mybuf="${match[9]}"
[[ -n "${match[5]}" ]] && match[2]="${match[5]}"
[[ -z "${match[2]}" ]] && break
# ADD
reply+=("$idx $end_idx ${HSMW_HIGHLIGHT_STYLES[dollar-double-quoted-argument]}")
idx+="${#match[1]}"
end_idx=idx+"${#match[2]}"
# ADD
reply+=("$idx $end_idx ${HSMW_HIGHLIGHT_STYLES[dollar-double-quoted-argument]}")
idx=end_idx
}
done
return 0