From 73cdb1e4bbad3c3058ea61a18df57f3b5b59cb21 Mon Sep 17 00:00:00 2001 From: romkatv Date: Mon, 25 Feb 2019 12:59:31 +0100 Subject: [PATCH] speed up widget rebinding by removing redundant array subscripts --- zsh-autosuggestions.zsh | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index d8f0151..69c0dc2 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -143,21 +143,10 @@ _zsh_autosuggest_feature_detect_zpty_returns_fd() { #--------------------------------------------------------------------# _zsh_autosuggest_incr_bind_count() { - if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then - ((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]++)) - else - _ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=1 - fi - - typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1] -} - -_zsh_autosuggest_get_bind_count() { - if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then - typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1] - else - typeset -gi bind_count=0 - fi + local C=${${_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]}:-0} + ((++C)) + _ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=$C + typeset -gi bind_count=$C } # Bind a single widget to an autosuggest widget, saving a reference to the original widget @@ -173,7 +162,9 @@ _zsh_autosuggest_bind_widget() { # Save a reference to the original widget case $widgets[$widget] in # Already bound - user:_zsh_autosuggest_(bound|orig)_*);; + user:_zsh_autosuggest_(bound|orig)_*) + bind_count=${${_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]}:-0} + ;; # User-defined widget user:*) @@ -195,8 +186,6 @@ _zsh_autosuggest_bind_widget() { ;; esac - _zsh_autosuggest_get_bind_count $widget - # Pass the original widget's name explicitly into the autosuggest # function. Use this passed in widget name to call the original # widget instead of relying on the $WIDGET variable being set