mirror of
https://github.com/zdharma-continuum/history-search-multi-word
synced 2024-11-22 03:13:09 +00:00
*highlight: Optimization: don't use 'true' and 'false' builtins
The result much more often reaches 18xx milliseconds. Below is almost the bottom value, which is ~1874 ms. ./parse -oo, after changes: Running time: 1.8982620000 num calls time self name ----------------------------------------------------------------------------------- 1) 350 1890,78 5,40 100,00% 1411,07 4,03 74,63% -hsmw-highlight-process 2) 2800 340,46 0,12 18,01% 340,46 0,12 18,01% -hsmw-highlight-string 3) 2450 80,94 0,03 4,28% 80,94 0,03 4,28% -hsmw-highlight-check-path 4) 1400 40,49 0,03 2,14% 40,49 0,03 2,14% -hsmw-highlight-main-type 5) 350 9,76 0,03 0,52% 9,76 0,03 0,52% -hsmw-highlight-stack-pop 6) 350 8,07 0,02 0,43% 8,07 0,02 0,43% -hsmw-highlight-path-separators 7) 1 0,01 0,01 0,00% 0,01 0,01 0,00% -hsmw-highlight-init
This commit is contained in:
parent
7eaa9f26aa
commit
594c4074fc
1 changed files with 14 additions and 14 deletions
|
@ -196,9 +196,9 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
|
||||||
local interactive_comments= # set to empty
|
local interactive_comments= # set to empty
|
||||||
fi
|
fi
|
||||||
if [[ -o ignore_braces ]] || eval '[[ -o ignore_close_braces ]] 2>/dev/null'; then
|
if [[ -o ignore_braces ]] || eval '[[ -o ignore_close_braces ]] 2>/dev/null'; then
|
||||||
local right_brace_is_recognised_everywhere=false
|
local right_brace_is_recognised_everywhere=0
|
||||||
else
|
else
|
||||||
local right_brace_is_recognised_everywhere=true
|
local right_brace_is_recognised_everywhere=1
|
||||||
fi
|
fi
|
||||||
if [[ -o path_dirs ]]; then
|
if [[ -o path_dirs ]]; then
|
||||||
integer path_dirs_was_set=1
|
integer path_dirs_was_set=1
|
||||||
|
@ -214,8 +214,8 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
|
||||||
setopt localoptions extendedglob bareglobqual nonomatch noksharrays
|
setopt localoptions extendedglob bareglobqual nonomatch noksharrays
|
||||||
|
|
||||||
## Variable declarations and initializations
|
## Variable declarations and initializations
|
||||||
local start_pos=0 end_pos highlight_glob=true arg style
|
local start_pos=0 end_pos highlight_glob=1 arg style
|
||||||
local in_array_assignment=false # true between 'a=(' and the matching ')'
|
local in_array_assignment=0 # true between 'a=(' and the matching ')'
|
||||||
integer arg_type=0 # Can be 0, 1, 2 or 3 - look up ^
|
integer arg_type=0 # Can be 0, 1, 2 or 3 - look up ^
|
||||||
local -a options_to_set # used in callees
|
local -a options_to_set # used in callees
|
||||||
local buf="$1"
|
local buf="$1"
|
||||||
|
@ -302,9 +302,9 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
|
||||||
integer already_added=0
|
integer already_added=0
|
||||||
style=unknown-token
|
style=unknown-token
|
||||||
if (( this_word & BIT_start )); then
|
if (( this_word & BIT_start )); then
|
||||||
in_array_assignment=false
|
in_array_assignment=0
|
||||||
if [[ $arg == 'noglob' ]]; then
|
if [[ $arg == 'noglob' ]]; then
|
||||||
highlight_glob=false
|
highlight_glob=0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
|
||||||
if [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] || [[ $arg == [0-9]##(|[+])=* ]]; then
|
if [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] || [[ $arg == [0-9]##(|[+])=* ]]; then
|
||||||
style=assign
|
style=assign
|
||||||
if [[ $arg[-1] == '(' ]]; then
|
if [[ $arg[-1] == '(' ]]; then
|
||||||
in_array_assignment=true
|
in_array_assignment=1
|
||||||
else
|
else
|
||||||
# assignment to a scalar parameter.
|
# assignment to a scalar parameter.
|
||||||
# (For array assignments, the command doesn't start until the ")" token.)
|
# (For array assignments, the command doesn't start until the ")" token.)
|
||||||
|
@ -529,9 +529,9 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
|
||||||
then # $arg is a non-command word
|
then # $arg is a non-command word
|
||||||
case $arg in
|
case $arg in
|
||||||
$'\x29') # subshell or end of array assignment
|
$'\x29') # subshell or end of array assignment
|
||||||
if $in_array_assignment; then
|
if (( in_array_assignment )); then
|
||||||
style=assign
|
style=assign
|
||||||
in_array_assignment=false
|
in_array_assignment=0
|
||||||
(( next_word = next_word | BIT_start ))
|
(( next_word = next_word | BIT_start ))
|
||||||
else
|
else
|
||||||
-hsmw-highlight-stack-pop 'R' style=reserved-word
|
-hsmw-highlight-stack-pop 'R' style=reserved-word
|
||||||
|
@ -549,7 +549,7 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
|
||||||
#
|
#
|
||||||
# Additionally, `tt(})' is recognized in any position if neither the
|
# Additionally, `tt(})' is recognized in any position if neither the
|
||||||
# tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set."""
|
# tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set."""
|
||||||
if $right_brace_is_recognised_everywhere; then
|
if (( right_brace_is_recognised_everywhere )); then
|
||||||
-hsmw-highlight-stack-pop 'Y' style=reserved-word
|
-hsmw-highlight-stack-pop 'Y' style=reserved-word
|
||||||
if [[ $style == reserved-word ]]; then
|
if [[ $style == reserved-word ]]; then
|
||||||
(( next_word = next_word | BIT_always ))
|
(( next_word = next_word | BIT_always ))
|
||||||
|
@ -575,8 +575,8 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
|
||||||
;;
|
;;
|
||||||
'`'*) style=back-quoted-argument;;
|
'`'*) style=back-quoted-argument;;
|
||||||
[*?]*|*[^\\][*?]*)
|
[*?]*|*[^\\][*?]*)
|
||||||
$highlight_glob && style=globbing || style=default;;
|
(( highlight_glob )) && style=globbing || style=default;;
|
||||||
*) if [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then
|
*) if [[ $arg = $'\x7d' ]] && (( right_brace_is_recognised_everywhere )); then
|
||||||
# was handled by the $'\x7d' case above
|
# was handled by the $'\x7d' case above
|
||||||
elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then
|
elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then
|
||||||
style=history-expansion
|
style=history-expansion
|
||||||
|
@ -600,12 +600,12 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
|
||||||
[[ $style == path || $style == path_prefix ]] && -hsmw-highlight-path-separators
|
[[ $style == path || $style == path_prefix ]] && -hsmw-highlight-path-separators
|
||||||
fi
|
fi
|
||||||
if (( arg_type == 3 )); then
|
if (( arg_type == 3 )); then
|
||||||
if [[ $arg == ';' ]] && $in_array_assignment; then
|
if [[ $arg == ';' ]] && (( in_array_assignment )); then
|
||||||
# literal newline inside an array assignment
|
# literal newline inside an array assignment
|
||||||
(( next_word = BIT_regular ))
|
(( next_word = BIT_regular ))
|
||||||
else
|
else
|
||||||
(( next_word = BIT_start ))
|
(( next_word = BIT_start ))
|
||||||
highlight_glob=true
|
highlight_glob=1
|
||||||
fi
|
fi
|
||||||
elif (( arg_type == 2 )) && (( this_word & BIT_start )); then
|
elif (( arg_type == 2 )) && (( this_word & BIT_start )); then
|
||||||
(( next_word = BIT_start ))
|
(( next_word = BIT_start ))
|
||||||
|
|
Loading…
Reference in a new issue