Reduce memory footprint

This commit is contained in:
Junegunn Choi 2013-11-03 04:05:32 +09:00
parent 2a0e0ded2a
commit d1298b8fff

18
fzf
View File

@ -104,7 +104,7 @@ when /darwin/
ret ret
end end
def self.nfc str, offset def self.nfc str, b, e
ret = '' ret = ''
omap = [] omap = []
pend = [] pend = []
@ -132,7 +132,7 @@ when /darwin/
ret << c ret << c
end end
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
end end
@ -315,7 +315,6 @@ searcher = Thread.new {
plcount = 0 # prev list count plcount = 0 # prev list count
q = '' q = ''
vcursor = 0 vcursor = 0
zz = [0, 0]
delay = -5 delay = -5
begin begin
@ -405,9 +404,9 @@ searcher = Thread.new {
if regexp if regexp
# Ignore errors: e.g. invalid byte sequence in UTF-8 # Ignore errors: e.g. invalid byte sequence in UTF-8
md = line.match(regexp) rescue nil md = line.match(regexp) rescue nil
md ? [line, md.offset(0)] : nil md ? [line, *md.offset(0)] : nil
else else
[line, zz] [line, 0, 0]
end end
}.compact }.compact
end) end)
@ -418,9 +417,9 @@ searcher = Thread.new {
mcount = matches.length mcount = matches.length
if @sort && mcount <= @sort if @sort && mcount <= @sort
matches.replace matches.sort_by { |pair| matches.replace matches.sort_by { |triple|
line, offset = pair line, b, e = triple
[offset.last - offset.first, line.length, line] [e - b, line.length, line]
} }
end end
end#new_search end#new_search
@ -450,10 +449,9 @@ searcher = Thread.new {
matches[0, max_items].each_with_index do |item, idx| matches[0, max_items].each_with_index do |item, idx|
next if !new_search && !((vcursor-1)..(vcursor+1)).include?(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 row = cursor_y - idx - 2
chosen = idx == vcursor chosen = idx == vcursor
b, e = offset
# Overflow # Overflow
if width(line) > maxc if width(line) > maxc