Improve performance of --nth
option (#90 contd.)
This commit is contained in:
parent
2d00abc7cb
commit
86c73105ee
9
fzf
9
fzf
@ -1106,15 +1106,18 @@ class FZF
|
|||||||
unless @delim
|
unless @delim
|
||||||
# AWK default
|
# AWK default
|
||||||
prefix_length = str.index(/\S/) || 0
|
prefix_length = str.index(/\S/) || 0
|
||||||
tokens = str.strip.scan(/\S+\s*/) rescue []
|
tokens = str.scan(/\S+\s*/) rescue []
|
||||||
else
|
else
|
||||||
prefix_length = 0
|
prefix_length = 0
|
||||||
tokens = str.scan(@delim) rescue []
|
tokens = str.scan(@delim) rescue []
|
||||||
end
|
end
|
||||||
@nth.map { |n|
|
@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,
|
[prefix_length + (tokens[0...(n.begin)] || []).join.length,
|
||||||
part.join.sub(/\s+$/, '')]
|
part.join]
|
||||||
|
end
|
||||||
}.compact
|
}.compact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user