aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-05 14:56:35 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-05 14:56:35 -0800
commitde668ce174f07e5b448703b10000437a552245d8 (patch)
treeb53dfba7b59084566dbfff10a071fd2114eee320
parent8cc12625047d7854bfd7ebee2082e69c9cafe566 (diff)
Low hanging optimization fruit.
-rw-r--r--nomsu.lua25
-rwxr-xr-xnomsu.moon10
2 files changed, 17 insertions, 18 deletions
diff --git a/nomsu.lua b/nomsu.lua
index 44b2fb0..e24cdb5 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -1114,31 +1114,26 @@ end)]]):format(concat(lua_bits, "\n"))
self:error("Nothing to get stub from")
end
if type(x) == 'string' then
- local patt = re.compile("{|(' '+ / '\n..' / {'\\'? '%' %id*} / {%id+} / {%op})*|}", {
- id = IDENT_CHAR,
- op = OPERATOR_CHAR
- })
- local spec = concat(patt:match(x), " ")
+ local spec = concat(self.__class.stub_patt:match(x), " ")
local stub = spec:gsub("%%%S+", "%%"):gsub("\\", "")
local arg_names
do
local _accum_0 = { }
local _len_0 = 1
- for arg in spec:gmatch("%%([^%s]*)") do
+ for arg in spec:gmatch("%%(%S*)") do
_accum_0[_len_0] = arg
_len_0 = _len_0 + 1
end
arg_names = _accum_0
end
- local escaped_args = set((function()
- local _accum_0 = { }
- local _len_0 = 1
+ local escaped_args
+ do
+ local _tbl_0 = { }
for arg in spec:gmatch("\\%%(%S*)") do
- _accum_0[_len_0] = arg
- _len_0 = _len_0 + 1
+ _tbl_0[arg] = true
end
- return _accum_0
- end)())
+ escaped_args = _tbl_0
+ end
return stub, arg_names, escaped_args
end
if type(x) ~= 'table' then
@@ -1421,6 +1416,10 @@ end)]]):format(concat(lua_bits, "\n"))
insert(bits, close)
return concat(bits)
end
+ self.stub_patt = re.compile("{|(' '+ / '\n..' / {'\\'? '%' %id*} / {%id+} / {%op})*|}", {
+ id = IDENT_CHAR,
+ op = OPERATOR_CHAR
+ })
NomsuCompiler = _class_0
end
if arg then
diff --git a/nomsu.moon b/nomsu.moon
index c7fac0d..896cd4b 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -748,6 +748,8 @@ end)]])\format(concat(lua_bits, "\n"))
tree = new_values
return tree
+ @stub_patt: re.compile "{|(' '+ / '\n..' / {'\\'? '%' %id*} / {%id+} / {%op})*|}",
+ id:IDENT_CHAR, op:OPERATOR_CHAR
get_stub: (x)=>
if not x
@error "Nothing to get stub from"
@@ -756,12 +758,10 @@ end)]])\format(concat(lua_bits, "\n"))
-- (e.g. "say %msg") or function call (e.g. FunctionCall({Word("say"), Var("msg")))
if type(x) == 'string'
-- Standardize format to stuff separated by spaces
- patt = re.compile "{|(' '+ / '\n..' / {'\\'? '%' %id*} / {%id+} / {%op})*|}",
- id:IDENT_CHAR, op:OPERATOR_CHAR
- spec = concat patt\match(x), " "
+ spec = concat @@stub_patt\match(x), " "
stub = spec\gsub("%%%S+","%%")\gsub("\\","")
- arg_names = [arg for arg in spec\gmatch("%%([^%s]*)")]
- escaped_args = set [arg for arg in spec\gmatch("\\%%(%S*)")]
+ arg_names = [arg for arg in spec\gmatch("%%(%S*)")]
+ escaped_args = {arg, true for arg in spec\gmatch("\\%%(%S*)")}
return stub, arg_names, escaped_args
if type(x) != 'table'
@error "Invalid type for getting stub: #{type(x)} for:\n#{repr x}"