Skip to content

Commit f56e3fa

Browse files
committed
'main': Optimize the path_prefix check.
Computing ${#array} is O(N), whereas checking 0 is O(1).
1 parent 62e2d05 commit f56e3fa

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

highlighters/main/main-highlighter.zsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,9 +1117,10 @@ _zsh_highlight_main_highlighter_check_path()
11171117
# If this word ends the buffer, check if it's the prefix of a valid path.
11181118
if (( has_end && (len == end_pos) )) &&
11191119
[[ $WIDGET != zle-line-finish ]]; then
1120+
# TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here.
11201121
local -a tmp
11211122
tmp=( ${expanded_path}*(N) )
1122-
(( $#tmp > 0 )) && REPLY=path_prefix && return 0
1123+
(( ${+tmp[1]} )) && REPLY=path_prefix && return 0
11231124
fi
11241125

11251126
# It's not a path.

0 commit comments

Comments
 (0)