From b52a485c5c8d161a1abeea7db9a1a8a44e527985 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 22 Apr 2016 14:12:49 +0000 Subject: [PATCH] brackets: Optimize a tiny bit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compute «${#BUFFER}» just once. I haven't measured the effect of this, but it might just avoid a strlen() every time around the loop, which could add up for large ${BUFFER}s. See issue #295. --- highlighters/brackets/brackets-highlighter.zsh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 2b87a3e..2571b58 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -48,10 +48,11 @@ _zsh_highlight_brackets_highlighter() { local level=0 pos local -A levelpos lastoflevel matching typepos + integer buflen=${#BUFFER} region_highlight=() # Find all brackets and remember which one is matching - for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do + for (( pos = 0; pos < buflen; pos++ )) ; do local char="$BUFFER[pos+1]" case $char in ["([{"]) @@ -68,9 +69,9 @@ _zsh_highlight_brackets_highlighter() ['"'\']) # Skip everything inside quotes local quotetype=$char - while (( $pos < ${#BUFFER} )) ; do + while (( pos < buflen )) ; do (( pos++ )) - [[ $BUFFER[$pos+1] == $quotetype ]] && break + [[ $BUFFER[pos+1] == $quotetype ]] && break done ;; esac