Skip to content

Commit cdd7f89

Browse files
committed
brackets: Optimize the character iteration
Test case: See the first comment of issue #295. Before: num calls time self name ----------------------------------------------------------------------------------- 1) 14 284.67 20.33 82.84% 284.67 20.33 82.84% _zsh_highlight_highlighter_brackets_paint 2) 15 313.72 20.91 91.30% 26.62 1.77 7.75% _zsh_highlight 3) 14 318.68 22.76 92.74% 7.41 0.53 2.16% _zsh_highlight_call_widget After: num calls time self name ----------------------------------------------------------------------------------- 1) 15 57.25 3.82 45.33% 28.30 1.89 22.41% _zsh_highlight 2) 14 81.96 5.85 64.90% 27.02 1.93 21.40% _zsh_highlight_call_widget 3) 14 26.31 1.88 20.84% 26.31 1.88 20.84% _zsh_highlight_highlighter_brackets_paint 4) 2 10.66 5.33 8.44% 8.97 4.49 7.10% VCS_INFO_formats 5) 2 25.92 12.96 20.52% 7.72 3.86 6.11% VCS_INFO_get_data_git (That's not in my everyday configuration but in my minimal testing setup, which runs vcs_info with the default settings.)
1 parent d62baa5 commit cdd7f89

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ to issue #418.
112112
revision zsh-5.8-172-gdd6e702ee or newer is also fine.)
113113
[#418, https://github.com/okapia/zsh-viexchange/issues/1]
114114

115+
- Improve performance of the `brackets` highlighter.
116+
115117

116118
# Changes in version 0.7.1
117119

highlighters/brackets/brackets-highlighter.zsh

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ _zsh_highlight_highlighter_brackets_paint()
5151
local -A levelpos lastoflevel matching
5252

5353
# Find all brackets and remember which one is matching
54-
for (( pos = 1; pos <= buflen; pos++ )) ; do
55-
char=$BUFFER[pos]
54+
pos=0
55+
for char in ${(s..)BUFFER} ; do
56+
(( ++pos ))
5657
case $char in
5758
["([{"])
5859
levelpos[$pos]=$((++level))

0 commit comments

Comments
 (0)