Skip to content

Commit ffef3c0

Browse files
committed
performance improvements
1 parent 6a10fde commit ffef3c0

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

nattlua/analyzer/control_flow.lua

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -245,26 +245,27 @@ return function(META)
245245
end
246246

247247
function META:PushCallFrame(obj, call_node, not_recursive_call)
248+
self.call_stack_map = self.call_stack_map or {}
249+
248250
if obj.recursively_called then return obj.recursively_called end
251+
249252
if
250253
self:IsRuntime() and
251254
call_node and
252255
not not_recursive_call and
253256
not obj:HasReferenceTypes()
254257
then
255-
for _, v in ipairs(self:GetCallStack()) do
256-
-- if the callnode is the same, we're doing some infinite recursion
257-
if v.call_node == call_node then
258-
if obj:IsExplicitOutputSignature() then
259-
-- so if we have explicit return types, just return those
260-
obj.recursively_called = obj:GetOutputSignature():Copy()
261-
return obj.recursively_called
262-
else
263-
-- if not we sadly have to resort to any
264-
-- TODO: error?
265-
obj.recursively_called = Tuple():AddRemainder(Tuple({Any()}):SetRepeat(math.huge))
266-
return obj.recursively_called
267-
end
258+
-- if the callnode is the same, we're doing some infinite recursion
259+
if self.call_stack_map[call_node] then
260+
if obj:IsExplicitOutputSignature() then
261+
-- so if we have explicit return types, just return those
262+
obj.recursively_called = obj:GetOutputSignature():Copy()
263+
return obj.recursively_called
264+
else
265+
-- if not we sadly have to resort to any
266+
-- TODO: error?
267+
obj.recursively_called = Tuple():AddRemainder(Tuple({Any()}):SetRepeat(math.huge))
268+
return obj.recursively_called
268269
end
269270
end
270271
end
@@ -280,18 +281,22 @@ return function(META)
280281
return Tuple():AddRemainder(Tuple({Any()}):SetRepeat(math.huge))
281282
end
282283

283-
self:PushContextValue(
284-
"call_stack",
285-
{
286-
obj = obj,
287-
call_node = call_node,
288-
scope = self:GetScope(),
289-
}
290-
)
284+
local val = {
285+
obj = obj,
286+
call_node = call_node,
287+
scope = self:GetScope(),
288+
}
289+
290+
if call_node then self.call_stack_map[call_node] = val end
291+
292+
self:PushContextValue("call_stack", val)
291293
end
292294

293295
function META:PopCallFrame()
296+
local val = self:GetCallFrame()
294297
self:PopContextValue("call_stack")
298+
299+
if val.call_node then self.call_stack_map[val.call_node] = nil end
295300
end
296301
end
297302

0 commit comments

Comments
 (0)