From e8cc271314612cf2aad1fe8e9e28d1a9c24ae0c8 Mon Sep 17 00:00:00 2001 From: Randy Date: Mon, 24 Mar 2014 08:45:34 +0200 Subject: [PATCH 1/2] Resolves slow performance in brackets highlighter --- highlighters/brackets/brackets-highlighter.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 8e635dd..ee4a83b 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -49,6 +49,7 @@ _zsh_highlight_brackets_highlighter() { local level=0 pos local -A levelpos lastoflevel matching typepos + region_highlight=() # Find all brackets and remember which one is matching for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do From 7edd08156e98b8be451bd5a034714746894b2a3d Mon Sep 17 00:00:00 2001 From: Randy Date: Sat, 29 Mar 2014 22:52:10 +0200 Subject: [PATCH 2/2] Chaned main highlighter alorithm to resolve issue #77 --- zsh-syntax-highlighting.zsh | 41 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index cdbe4c4..65f1938 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -54,37 +54,42 @@ _zsh_highlight() # Do not highlight if there are pending inputs (copy/paste). [[ $PENDING -gt 0 ]] && return $ret + # Reset region highlight to build it from scratch + region_highlight=(); + { - local -a selected_highlighters local cache_place + local -a region_highlight_copy # Select which highlighters in ZSH_HIGHLIGHT_HIGHLIGHTERS need to be invoked. local highlighter; for highlighter in $ZSH_HIGHLIGHT_HIGHLIGHTERS; do + # eval cache place for current highlighter and prepare it + cache_place="_zsh_highlight_${highlighter}_highlighter_cache" + typeset -ga ${cache_place} + # If highlighter needs to be invoked if "_zsh_highlight_${highlighter}_highlighter_predicate"; then - # Mark the highlighter as selected for update. - selected_highlighters+=($highlighter) + # save a copy, and cleanup region_highlight + region_highlight_copy=("${region_highlight[@]}") + region_highlight=() - # Remove what was stored in its cache from region_highlight. - cache_place="_zsh_highlight_${highlighter}_highlighter_cache" - typeset -ga ${cache_place} - [[ ${#${(P)cache_place}} -gt 0 ]] && [[ ! -z ${region_highlight-} ]] && region_highlight=(${region_highlight:#(${(P~j.|.)cache_place})}) + # Execute highlighter and save result + { + "_zsh_highlight_${highlighter}_highlighter" + } always { + eval "${cache_place}=(\"\${region_highlight[@]}\")" + } + + # Restore saved region_highlight + region_highlight=("${region_highlight_copy[@]}") fi - done - # Invoke each selected highlighter and store the result in its cache. - local -a region_highlight_copy - for highlighter in $selected_highlighters; do - cache_place="_zsh_highlight_${highlighter}_highlighter_cache" - region_highlight_copy=($region_highlight) - { - "_zsh_highlight_${highlighter}_highlighter" - } always { - [[ ! -z ${region_highlight-} ]] && : ${(PA)cache_place::=${region_highlight:#(${(~j.|.)region_highlight_copy})}} - } + # Use value form cache if any cached + eval "region_highlight+=(\"\${${cache_place}[@]}\")" + done } always {