Low hanging optimization fruit.

This commit is contained in:
Bruce Hill 2018-01-05 14:56:35 -08:00
parent 8cc1262504
commit de668ce174
2 changed files with 17 additions and 18 deletions

View File

@ -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

View File

@ -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}"