summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2013-11-03 04:05:32 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2013-11-03 04:05:32 +0900
commitd1298b8fff828bc1a2debee0c881de02213d138e (patch)
tree95853abf85fe9f5e04db958e433f16d81a7eafc9
parent2a0e0ded2a11f26119a40c4c7483ff979e777c15 (diff)
Reduce memory footprint
-rwxr-xr-xfzf18
1 files changed, 8 insertions, 10 deletions
diff --git a/fzf b/fzf
index d483b4aa..91409393 100755
--- a/fzf
+++ b/fzf
@@ -104,7 +104,7 @@ when /darwin/
ret
end
- def self.nfc str, offset
+ def self.nfc str, b, e
ret = ''
omap = []
pend = []
@@ -132,7 +132,7 @@ when /darwin/
ret << c
end
end
- return [ret, offset.map { |o| omap[o] || (omap.last + 1) }]
+ return [ret, omap[b] || 0, omap[e] || (omap.last || 0 + 1)]
end
end
@@ -315,7 +315,6 @@ searcher = Thread.new {
plcount = 0 # prev list count
q = ''
vcursor = 0
- zz = [0, 0]
delay = -5
begin
@@ -405,9 +404,9 @@ searcher = Thread.new {
if regexp
# Ignore errors: e.g. invalid byte sequence in UTF-8
md = line.match(regexp) rescue nil
- md ? [line, md.offset(0)] : nil
+ md ? [line, *md.offset(0)] : nil
else
- [line, zz]
+ [line, 0, 0]
end
}.compact
end)
@@ -418,9 +417,9 @@ searcher = Thread.new {
mcount = matches.length
if @sort && mcount <= @sort
- matches.replace matches.sort_by { |pair|
- line, offset = pair
- [offset.last - offset.first, line.length, line]
+ matches.replace matches.sort_by { |triple|
+ line, b, e = triple
+ [e - b, line.length, line]
}
end
end#new_search
@@ -450,10 +449,9 @@ searcher = Thread.new {
matches[0, max_items].each_with_index do |item, idx|
next if !new_search && !((vcursor-1)..(vcursor+1)).include?(idx)
- line, offset = convert_item item
+ line, b, e = convert_item item
row = cursor_y - idx - 2
chosen = idx == vcursor
- b, e = offset
# Overflow
if width(line) > maxc