summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-05-13 10:47:35 +0800
committer最萌小汐 <sumneko@hotmail.com>2024-05-13 10:47:35 +0800
commit5093bca814e5f3471b1be28f1c9d71d6be388e60 (patch)
treef8898c333132c8acda799ea859f980718e043db3 /script
parent0df588358e9343ff50f1d68b12d971e50bbe7e7d (diff)
downloadlua-language-server-5093bca814e5f3471b1be28f1c9d71d6be388e60.zip
优化性能
Diffstat (limited to 'script')
-rw-r--r--script/vm/function.lua33
1 files changed, 26 insertions, 7 deletions
diff --git a/script/vm/function.lua b/script/vm/function.lua
index 1a916a1c..1e308317 100644
--- a/script/vm/function.lua
+++ b/script/vm/function.lua
@@ -1,6 +1,7 @@
---@class vm
local vm = require 'vm.vm'
local guide = require 'parser.guide'
+local util = require 'utility'
---@param arg parser.object
---@return parser.object?
@@ -360,18 +361,28 @@ function vm.getExactMatchedFunctions(func, args)
if not args or not funcs then
return funcs
end
+ if #funcs == 1 then
+ return funcs
+ end
local uri = guide.getUri(func)
- local result = {}
- for _, n in ipairs(funcs) do
- if not vm.isVarargFunctionWithOverloads(n)
- and isAllParamMatched(uri, args, n.args) then
- result[#result+1] = n
+ local needRemove
+ for i, n in ipairs(funcs) do
+ if vm.isVarargFunctionWithOverloads(n)
+ or not isAllParamMatched(uri, args, n.args) then
+ if not needRemove then
+ needRemove = {}
+ end
+ needRemove[#needRemove+1] = i
end
end
- if #result == 0 then
+ if not needRemove then
+ return funcs
+ end
+ if #needRemove == #funcs then
return nil
end
- return result
+ util.tableMultiRemove(funcs, needRemove)
+ return funcs
end
---@param func parser.object
@@ -414,23 +425,31 @@ function vm.isVarargFunctionWithOverloads(func)
if not func.args then
return false
end
+ if func._varargFunction ~= nil then
+ return func._varargFunction
+ end
if func.args[1] and func.args[1].type == 'self' then
if not func.args[2] or func.args[2].type ~= '...' then
+ func._varargFunction = false
return false
end
else
if not func.args[1] or func.args[1].type ~= '...' then
+ func._varargFunction = false
return false
end
end
if not func.bindDocs then
+ func._varargFunction = false
return false
end
for _, doc in ipairs(func.bindDocs) do
if doc.type == 'doc.overload' then
+ func._varargFunction = true
return true
end
end
+ func._varargFunction = false
return false
end