From 314272c3763e85dd5f4d63b10417708afc280412 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Mon, 30 Dec 2013 01:52:13 -0800 Subject: [PATCH] don't create unnecessary tables --- moonscript/transform/names.lua | 38 ++++++++++++--------------------- moonscript/transform/names.moon | 14 ++++++------ 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/moonscript/transform/names.lua b/moonscript/transform/names.lua index abc0d5b..a7584da 100644 --- a/moonscript/transform/names.lua +++ b/moonscript/transform/names.lua @@ -47,31 +47,21 @@ do return self.name end, chain = function(self, ...) - local items - do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = { - ... - } - for _index_0 = 1, #_list_0 do - local i = _list_0[_index_0] - if type(i) == "string" then - _accum_0[_len_0] = { - "dot", - i - } - else - _accum_0[_len_0] = i - end - _len_0 = _len_0 + 1 - end - items = _accum_0 - end - return build.chain({ + local items = { base = self, - unpack(items) - }) + ... + } + for k, v in ipairs(items) do + if type(v) == "string" then + items[k] = { + "dot", + v + } + else + items[k] = v + end + end + return build.chain(items) end, index = function(self, key) if type(key) == "string" then diff --git a/moonscript/transform/names.moon b/moonscript/transform/names.moon index daf17ed..220d862 100644 --- a/moonscript/transform/names.moon +++ b/moonscript/transform/names.moon @@ -18,16 +18,14 @@ class NameProxy @name chain: (...) => - items = for i in *{...} - if type(i) == "string" - {"dot", i} + items = { base: @, ... } + for k,v in ipairs items + items[k] = if type(v) == "string" + {"dot", v} else - i + v - build.chain { - base: self - unpack items - } + build.chain items index: (key) => if type(key) == "string"