Skip to content
Myr

Improve performance of `--nth` option (#90)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 1e07b3b · Browse files · 1 file+19 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+19 added−16 removed

  • other:+19 added−16 removed

1 file+19 added−16 removed

modified:fzf+19 added-16 removed
5 unmodified lines
6# / /_/_ / / /_7# / __/ / /_/ __/8# /_/ /___/_/ Fuzzy finder for your shell9#10# Version: 0.8.7 (Jul 27, 2014)10# Version: 0.8.7 (Aug 15, 2014)11#12# Author: Junegunn Choi13# URL: https://github.com/junegunn/fzf14# License: MIT
1086 unmodified lines
1101 end11021103 def tokenize str1104 @tokens_cache[str] ||=1105 begin1105 unless @delim1106 # AWK default1107 prefix_length = str[/^\s+/].length rescue 01108 [prefix_length, (str.strip.scan(/\S+\s*/) rescue [])]1109 else1110 prefix_length = 01111 [prefix_length, (str.scan(@delim) rescue [])]1106 unless @delim1107 # AWK default1108 prefix_length = str.index(/\S/) || 01109 tokens = str.strip.scan(/\S+\s*/) rescue []1110 else1111 prefix_length = 01112 tokens = str.scan(@delim) rescue []1113 end1114 @nth.map { |n|1115 (part = tokens[n]) &&1116 [prefix_length + (tokens[0...(n.begin)] || []).join.length,1117 part.join.sub(/\s+$/, '')]1118 }.compact1119 end1120 end11211122 def do_match str, pat1123 if @nth1117 prefix_length, tokens = tokenize str11181119 @nth.each do |n|1120 if (range = tokens[n]) && (token = range.join) &&1121 (md = token.sub(/\s+$/, '').match(pat) rescue nil)1122 prefix_length += (tokens[0...(n.begin)] || []).join.length1123 offset = md.offset(0).map { |o| o + prefix_length }1124 return MatchData.new(offset)1124 tokenize(str).each do |pair|1125 prefix_length, token = pair1126 if md = token.match(pat) rescue nil1127 return MatchData.new(md.offset(0).map { |o| o + prefix_length })1128 end1129 end1130 nil1131 else
137 unmodified lines