Skip to content

Commit 5093bca

Browse files
committed
优化性能
1 parent 0df5883 commit 5093bca

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

script/vm/function.lua

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---@class vm
22
local vm = require 'vm.vm'
33
local guide = require 'parser.guide'
4+
local util = require 'utility'
45

56
---@param arg parser.object
67
---@return parser.object?
@@ -360,18 +361,28 @@ function vm.getExactMatchedFunctions(func, args)
360361
if not args or not funcs then
361362
return funcs
362363
end
364+
if #funcs == 1 then
365+
return funcs
366+
end
363367
local uri = guide.getUri(func)
364-
local result = {}
365-
for _, n in ipairs(funcs) do
366-
if not vm.isVarargFunctionWithOverloads(n)
367-
and isAllParamMatched(uri, args, n.args) then
368-
result[#result+1] = n
368+
local needRemove
369+
for i, n in ipairs(funcs) do
370+
if vm.isVarargFunctionWithOverloads(n)
371+
or not isAllParamMatched(uri, args, n.args) then
372+
if not needRemove then
373+
needRemove = {}
374+
end
375+
needRemove[#needRemove+1] = i
369376
end
370377
end
371-
if #result == 0 then
378+
if not needRemove then
379+
return funcs
380+
end
381+
if #needRemove == #funcs then
372382
return nil
373383
end
374-
return result
384+
util.tableMultiRemove(funcs, needRemove)
385+
return funcs
375386
end
376387

377388
---@param func parser.object
@@ -414,23 +425,31 @@ function vm.isVarargFunctionWithOverloads(func)
414425
if not func.args then
415426
return false
416427
end
428+
if func._varargFunction ~= nil then
429+
return func._varargFunction
430+
end
417431
if func.args[1] and func.args[1].type == 'self' then
418432
if not func.args[2] or func.args[2].type ~= '...' then
433+
func._varargFunction = false
419434
return false
420435
end
421436
else
422437
if not func.args[1] or func.args[1].type ~= '...' then
438+
func._varargFunction = false
423439
return false
424440
end
425441
end
426442
if not func.bindDocs then
443+
func._varargFunction = false
427444
return false
428445
end
429446
for _, doc in ipairs(func.bindDocs) do
430447
if doc.type == 'doc.overload' then
448+
func._varargFunction = true
431449
return true
432450
end
433451
end
452+
func._varargFunction = false
434453
return false
435454
end
436455

0 commit comments

Comments
 (0)