Skip to content

Commit b39bbd0

Browse files
authored
perf: Optimize contains_call() by adding memoization (#105)
1 parent 7897788 commit b39bbd0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/luacheck/stages/resolve_locals.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,26 @@ local function in_scope(var, index)
7979
end
8080

8181
local function contains_call(node)
82+
if node._contains_call ~= nil then
83+
-- return cached result
84+
return node._contains_call
85+
end
86+
8287
if node.tag == "Call" or node.tag == "Invoke" then
88+
node._contains_call = true
8389
return true
8490
end
8591

8692
if node.tag ~= "Function" then
8793
for _, sub_node in ipairs(node) do
8894
if type(sub_node) == 'table' and contains_call(sub_node) then
95+
node._contains_call = true
8996
return true
9097
end
9198
end
9299
end
93100

101+
node._contains_call = false
94102
return false
95103
end
96104

0 commit comments

Comments
 (0)