mirror of
https://github.com/zdharma-continuum/history-search-multi-word
synced 2024-11-21 19:03:11 +00:00
*highlighting: Optimization – remove *add-highlight function
parse.zsh -o, before changes: Running time: 0.9516510000 num calls time self name ----------------------------------------------------------------------------------- 1) 350 945,28 2,70 100,00% 632,08 1,81 66,87% -hsmw-highlight-process 2) 3150 62,92 0,02 6,66% 62,92 0,02 6,66% -hsmw-add-highlight 3) 950 80,01 0,08 8,46% 58,97 0,06 6,24% -hsmw-highlight-check-path 4) 300 58,21 0,19 6,16% 57,09 0,19 6,04% -hsmw-highlight-string 5) 1950 43,18 0,02 4,57% 43,18 0,02 4,57% -hsmw-highlight-expand-path 6) 1000 36,50 0,04 3,86% 36,50 0,04 3,86% -hsmw-highlight-main-type 7) 1000 28,77 0,03 3,04% 28,77 0,03 3,04% (anon) 8) 3100 19,17 0,01 2,03% 19,17 0,01 2,03% -hsmw-highlight-is-redirection parse.zsh -o, after changes: Running time: 0.8807530000 num calls time self name ----------------------------------------------------------------------------------- 1) 350 874,42 2,50 100,00% 630,15 1,80 72,06% -hsmw-highlight-process 2) 950 78,16 0,08 8,94% 57,66 0,06 6,59% -hsmw-highlight-check-path 3) 300 57,42 0,19 6,57% 57,42 0,19 6,57% -hsmw-highlight-string 4) 1950 41,83 0,02 4,78% 41,83 0,02 4,78% -hsmw-highlight-expand-path 5) 1000 33,57 0,03 3,84% 33,57 0,03 3,84% -hsmw-highlight-main-type 6) 1000 28,36 0,03 3,24% 28,36 0,03 3,24% (anon) 7) 3100 18,92 0,01 2,16% 18,92 0,01 2,16% -hsmw-highlight-is-redirection 8) 200 3,20 0,02 0,37% 3,20 0,02 0,37% -hsmw-highlight-check-assign ( 1084 - 847 ) / 1084.0 = 0.2186
This commit is contained in:
parent
8acdd8bd5b
commit
60710d31b5
1 changed files with 21 additions and 19 deletions
|
@ -334,7 +334,8 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
|
|||
else
|
||||
style=unknown-token # prematurely terminated
|
||||
fi
|
||||
-hsmw-add-highlight $start_pos $end_pos $style
|
||||
# ADD
|
||||
reply+=("$start_pos $end_pos ${HSMW_HIGHLIGHT_STYLES[$style]}")
|
||||
already_added=1
|
||||
continue
|
||||
fi
|
||||
|
@ -478,10 +479,12 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
|
|||
# We highlight just the opening parentheses, as a reserved word; this
|
||||
# is how [[ ... ]] is highlighted, too.
|
||||
style=reserved-word
|
||||
-hsmw-add-highlight $start_pos $((start_pos + 2)) $style
|
||||
# ADD
|
||||
reply+=("$start_pos $(( start_pos + 2 )) ${HSMW_HIGHLIGHT_STYLES[$style]}")
|
||||
already_added=1
|
||||
if [[ $arg[-2,-1] == '))' ]]; then
|
||||
-hsmw-add-highlight $((end_pos - 2)) $end_pos $style
|
||||
# ADD
|
||||
reply+=("$(( end_pos - 2 )) $end_pos ${HSMW_HIGHLIGHT_STYLES[$style]}")
|
||||
already_added=1
|
||||
fi
|
||||
elif [[ $arg == '()' ]]; then
|
||||
|
@ -499,7 +502,9 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
|
|||
fi
|
||||
fi
|
||||
;;
|
||||
*) -hsmw-add-highlight $start_pos $end_pos commandtypefromthefuture-$REPLY
|
||||
*)
|
||||
# ADD
|
||||
reply+=("$start_pos $end_pos commandtypefromthefuture-$REPLY")
|
||||
already_added=1
|
||||
;;
|
||||
esac
|
||||
|
@ -543,12 +548,14 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
|
|||
'-'*) style=single-hyphen-option;;
|
||||
"'"*) style=single-quoted-argument;;
|
||||
'"'*) style=double-quoted-argument
|
||||
-hsmw-add-highlight $start_pos $end_pos $style
|
||||
# ADD
|
||||
reply+=("$start_pos $end_pos ${HSMW_HIGHLIGHT_STYLES[$style]}")
|
||||
-hsmw-highlight-string
|
||||
already_added=1
|
||||
;;
|
||||
\$\'*) style=dollar-quoted-argument
|
||||
-hsmw-add-highlight $start_pos $end_pos $style
|
||||
# ADD
|
||||
reply+=("$start_pos $end_pos ${HSMW_HIGHLIGHT_STYLES[$style]}")
|
||||
-hsmw-highlight-dollar-string
|
||||
already_added=1
|
||||
;;
|
||||
|
@ -579,7 +586,8 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
|
|||
esac
|
||||
fi
|
||||
if ! (( already_added )); then
|
||||
-hsmw-add-highlight $start_pos $end_pos $style
|
||||
# ADD
|
||||
reply+=("$start_pos $end_pos ${HSMW_HIGHLIGHT_STYLES[$style]}")
|
||||
[[ $style == path || $style == path_prefix ]] && -hsmw-highlight-path-separators
|
||||
fi
|
||||
if [[ -n ${(M)__HSMW_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
|
||||
|
@ -631,7 +639,8 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
|
|||
[[ -z "$HSMW_HIGHLIGHT_STYLES[$style_pathsep]" || "$HSMW_HIGHLIGHT_STYLES[$style]" == "$HSMW_HIGHLIGHT_STYLES[$style_pathsep]" ]] && return 0
|
||||
for (( pos = start_pos; $pos <= end_pos; pos++ )) ; do
|
||||
if [[ ${buf[pos]} == "/" ]]; then
|
||||
-hsmw-add-highlight $((pos - 1)) $pos $style_pathsep
|
||||
# ADD
|
||||
reply+=("$(( pos - 1 )) $pos ${HSMW_HIGHLIGHT_STYLES[$style_pathsep]}")
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -704,7 +713,8 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
|
|||
*) continue ;;
|
||||
|
||||
esac
|
||||
-hsmw-add-highlight $j $k $style
|
||||
# ADD
|
||||
reply+=("$j $k ${HSMW_HIGHLIGHT_STYLES[$style]}")
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -747,7 +757,8 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
|
|||
*) continue ;;
|
||||
|
||||
esac
|
||||
-hsmw-add-highlight $j $k $style
|
||||
# ADD
|
||||
reply+=("$j $k ${HSMW_HIGHLIGHT_STYLES[$style]}")
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -772,15 +783,6 @@ typeset -gA HSMW_HIGHLIGHT_STYLES
|
|||
__hsmw_highlight_main__command_type_cache=()
|
||||
}
|
||||
|
||||
#
|
||||
# $1 - start position
|
||||
# $2 - end position
|
||||
# $3 - style name
|
||||
-hsmw-add-highlight()
|
||||
{
|
||||
(( ${+HSMW_HIGHLIGHT_STYLES[$3]} )) && reply+=("$1 $2 ${HSMW_HIGHLIGHT_STYLES[$3]}")
|
||||
}
|
||||
|
||||
__HSMW_MH_SOURCED=1
|
||||
|
||||
# vim:ft=zsh
|
||||
|
|
Loading…
Reference in a new issue