append avoids creating table for varargs

This commit is contained in:
leaf corcoran 2014-03-05 23:09:43 -08:00
parent 8851f803fb
commit db8f5398fc
2 changed files with 28 additions and 38 deletions

View File

@ -150,38 +150,30 @@ end
do do
local _base_0 = { local _base_0 = {
pos = nil, pos = nil,
_append_single = function(self, item)
if Line == mtype(item) then
if not (self.pos) then
self.pos = item.pos
end
for _index_0 = 1, #item do
local value = item[_index_0]
self:_append_single(value)
end
else
insert(self, item)
end
return nil
end,
append_list = function(self, items, delim) append_list = function(self, items, delim)
for i = 1, #items do for i = 1, #items do
self:_append_single(items[i]) self:append(items[i])
if i < #items then if i < #items then
insert(self, delim) insert(self, delim)
end end
end end
return nil return nil
end, end,
append = function(self, ...) append = function(self, first, ...)
local _list_0 = { if Line == mtype(first) then
... if not (self.pos) then
} self.pos = first.pos
for _index_0 = 1, #_list_0 do end
local item = _list_0[_index_0] for _index_0 = 1, #first do
self:_append_single(item) local value = first[_index_0]
self:append(value)
end
else
insert(self, first)
end
if ... then
return self:append(...)
end end
return nil
end, end,
render = function(self, buffer) render = function(self, buffer)
local current = { } local current = { }
@ -209,7 +201,7 @@ do
insert(current, chunk) insert(current, chunk)
end end
end end
if #current > 0 then if current[1] then
add_current() add_current()
end end
return buffer return buffer

View File

@ -97,24 +97,22 @@ class Lines
class Line class Line
pos: nil pos: nil
_append_single: (item) =>
if Line == mtype item
-- print "appending line to line", item.pos, item
@pos = item.pos unless @pos -- bubble pos if there isn't one
@_append_single value for value in *item
else
insert self, item
nil
append_list: (items, delim) => append_list: (items, delim) =>
for i = 1,#items for i = 1,#items
@_append_single items[i] @append items[i]
if i < #items then insert self, delim if i < #items then insert self, delim
nil nil
append: (...) => append: (first, ...) =>
@_append_single item for item in *{...} if Line == mtype first
nil -- print "appending line to line", first.pos, first
@pos = first.pos unless @pos -- bubble pos if there isn't one
@append value for value in *first
else
insert self, first
if ...
@append ...
-- todo: try to remove concats from here -- todo: try to remove concats from here
render: (buffer) => render: (buffer) =>
@ -137,7 +135,7 @@ class Line
else else
insert current, chunk insert current, chunk
if #current > 0 if current[1]
add_current! add_current!
buffer buffer