summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2013-10-29 15:46:19 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2013-10-29 15:46:19 +0900
commit856dad4ac80b1162db7ff86bdbaa7e0ae30ca607 (patch)
tree17c32af041296a226c8e376234bd97e025d228a0
parentbf71b1767d1cb04499eab16183b114a7d6395122 (diff)
Choose between prefix cache and suffix cache
-rwxr-xr-xfzf16
1 files changed, 11 insertions, 5 deletions
diff --git a/fzf b/fzf
index 1e3612b2..4a605afa 100755
--- a/fzf
+++ b/fzf
@@ -359,13 +359,19 @@ searcher = Thread.new {
list, cache = pair
found.concat(cache[q] ||= begin
- prefix_cache = nil
- (q.length - 1).downto(1) do |len|
- prefix = q[0, len]
- break if prefix_cache = cache[prefix]
+ prefix, suffix = @query[0, @cursor_x], @query[@cursor_x..-1] || ''
+ prefix_cache = suffix_cache = nil
+
+ (prefix.length - 1).downto(1) do |len|
+ break if prefix_cache = cache[prefix[0, len]]
end
- (prefix_cache ? prefix_cache.map { |e| e.first } : list).map { |line|
+ 0.upto(suffix.length - 1) do |idx|
+ break if suffix_cache = cache[suffix[idx..-1]]
+ end unless suffix.empty?
+
+ partial_cache = [prefix_cache, suffix_cache].compact.sort_by { |e| e.length }.first
+ (partial_cache ? partial_cache.map { |e| e.first } : list).map { |line|
if regexp
# Ignore errors: e.g. invalid byte sequence in UTF-8
md = line.match(regexp) rescue nil