'main': Optimize the path_prefix check.

Computing ${#array} is O(N), whereas checking 0 is O(1).
This commit is contained in:
Daniel Shahaf 2020-03-16 20:45:56 +00:00
parent 62e2d05f91
commit f56e3fad23

View File

@ -1117,9 +1117,10 @@ _zsh_highlight_main_highlighter_check_path()
# If this word ends the buffer, check if it's the prefix of a valid path.
if (( has_end && (len == end_pos) )) &&
[[ $WIDGET != zle-line-finish ]]; then
# TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here.
local -a tmp
tmp=( ${expanded_path}*(N) )
(( $#tmp > 0 )) && REPLY=path_prefix && return 0
(( ${+tmp[1]} )) && REPLY=path_prefix && return 0
fi
# It's not a path.