From 86c73105ee25ce688d6c05902a198fb7ea8a70a9 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 15 Aug 2014 04:01:37 +0900 Subject: [PATCH] Improve performance of `--nth` option (#90 contd.) --- fzf | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fzf b/fzf index 935944d..791fc3b 100755 --- a/fzf +++ b/fzf @@ -1106,15 +1106,18 @@ class FZF unless @delim # AWK default prefix_length = str.index(/\S/) || 0 - tokens = str.strip.scan(/\S+\s*/) rescue [] + tokens = str.scan(/\S+\s*/) rescue [] else prefix_length = 0 tokens = str.scan(@delim) rescue [] end @nth.map { |n| - (part = tokens[n]) && + if n.begin == 0 && n.end == -1 + [prefix_length, tokens.join] + elsif part = tokens[n] [prefix_length + (tokens[0...(n.begin)] || []).join.length, - part.join.sub(/\s+$/, '')] + part.join] + end }.compact end end