Skip to content

Commit ee7c3ef

Browse files
committed
compute table keys once
1 parent 60f4c79 commit ee7c3ef

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

script/vm/type.lua

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ function vm.isSubType(uri, child, parent, mark, errs)
327327
local weakNil = config.get(uri, 'Lua.type.weakNilCheck')
328328
local skipTable
329329
for n in child:eachObject() do
330-
if skipTable == nil and n.type == "table" and parent.type == "vm.node" then -- skip table type check if child is has class
330+
if skipTable == nil and n.type == "table" and parent.type == "vm.node" then -- skip table type check if child has class
331331
---@cast parent vm.node
332332
for _, c in ipairs(child) do
333333
if c.type == 'global' and c.cate == 'type' then
@@ -486,19 +486,20 @@ function vm.isSubType(uri, child, parent, mark, errs)
486486
local set = parent:getSets(uri)
487487
local missedKeys = {}
488488
local failedCheck
489-
490-
local myKeys = {}
491-
for _, field in ipairs(child) do
492-
local key = vm.getKeyName(field) or field.tindex
493-
if key then
494-
myKeys[key] = vm.compileNode(field)
495-
end
496-
end
497-
489+
local myKeys
498490
for _, def in ipairs(set) do
499491
if not def.fields or #def.fields == 0 then
500492
goto continue
501493
end
494+
if not myKeys then
495+
myKeys = {}
496+
for _, field in ipairs(child) do
497+
local key = vm.getKeyName(field) or field.tindex
498+
if key then
499+
myKeys[key] = vm.compileNode(field)
500+
end
501+
end
502+
end
502503

503504
for _, field in ipairs(def.fields) do
504505
local key = vm.getKeyName(field)
@@ -512,6 +513,7 @@ function vm.isSubType(uri, child, parent, mark, errs)
512513
if not key then
513514
goto continue
514515
end
516+
515517
local ok
516518
local nodeField = vm.compileNode(field)
517519
if myKeys[key] then

0 commit comments

Comments
 (0)