From 63816c5da84e177ecb1d509f7b7255df05022083 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Fri, 10 Jun 2016 13:24:45 -0600 Subject: [PATCH] Fix #164: Use `fc` builtin instead of `$history` array for lookup According to a few tests, the `fc` builtin appears to be quite a bit faster than searching through the `$history` associative array when dealing with large history files (500K+). --- src/strategies/default.zsh | 9 +-------- zsh-autosuggestions.zsh | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/strategies/default.zsh b/src/strategies/default.zsh index 42da24e..29333f5 100644 --- a/src/strategies/default.zsh +++ b/src/strategies/default.zsh @@ -7,12 +7,5 @@ # _zsh_autosuggest_strategy_default() { - local prefix="$1" - - # Get the keys of the history items that match - local -a histkeys - histkeys=(${(k)history[(r)$prefix*]}) - - # Echo the value of the first key - echo -E "${history[$histkeys[1]]}" + fc -lnrm "$1*" 1 2>/dev/null | head -n 1 } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index d2c7d2c..9f25514 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -371,14 +371,7 @@ _zsh_autosuggest_escape_command() { # _zsh_autosuggest_strategy_default() { - local prefix="$1" - - # Get the keys of the history items that match - local -a histkeys - histkeys=(${(k)history[(r)$prefix*]}) - - # Echo the value of the first key - echo -E "${history[$histkeys[1]]}" + fc -lnrm "$1*" 1 2>/dev/null | head -n 1 } #--------------------------------------------------------------------#