summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-17 14:22:47 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-17 14:22:47 +0800
commit41d83a00788d2232ef6781ee337acc3d0c380bf2 (patch)
treef75e558ae0790f71542ba41246f1c32bb2f4d0c0
parent52f34152d4f8237382ee05790df204643f6f3864 (diff)
downloadlua-language-server-41d83a00788d2232ef6781ee337acc3d0c380bf2.zip
优化性能
-rw-r--r--script-beta/vm/eachRef.lua49
1 files changed, 31 insertions, 18 deletions
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index 6348c7ef..456e59e1 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -440,18 +440,19 @@ local function applyCache(cache, callback, max)
end
end
-local function eachRef(source, callback)
- local list = { source }
- local mark = {}
- local result = {}
- local state = {}
+local function eachRef(source, result)
+ local list = { source }
+ local mark = {}
+ local state = {}
+ local hasOf = {}
+ local hasCheck = {}
local function found(src, mode)
local info
if src.mode then
info = src
src = info.source
end
- if not mark[src] then
+ if mark[src] == nil then
list[#list+1] = src
end
if info then
@@ -461,27 +462,42 @@ local function eachRef(source, callback)
source = src,
mode = mode,
}
+ else
+ mark[src] = mark[src] or false
end
end
for _ = 1, 1000 do
- if _ == 1000 then
- warn('stack overflow!')
- break
- end
local max = #list
if max == 0 then
break
end
local src = list[max]
list[max] = nil
- vm.refOf(state, src, found)
+ if not hasOf[src] then
+ hasOf[src] = true
+ vm.refOf(state, src, found)
+ end
+ if not hasCheck[src] then
+ hasCheck[src] = true
+ vm.refCheck(state, src, found)
+ end
end
for _, info in pairs(mark) do
- result[#result+1] = info
+ if info then
+ result[#result+1] = info
+ end
end
return result
end
+function vm.refCheck(state, source, callback)
+ checkValue(state, source, callback)
+ checkAsArg(state, source, callback)
+ checkAsReturn(state, source, callback)
+ checkAsParen(state, source, callback)
+ checkSetValue(state, source, callback)
+end
+
function vm.refOf(state, source, callback)
local stype = source.type
if stype == 'local' then
@@ -524,11 +540,6 @@ function vm.refOf(state, source, callback)
elseif stype == 'paren' then
vm.refOf(state, source.exp, callback)
end
- checkValue(state, source, callback)
- checkAsArg(state, source, callback)
- checkAsReturn(state, source, callback)
- checkAsParen(state, source, callback)
- checkSetValue(state, source, callback)
end
--- 判断2个对象是否拥有相同的引用
@@ -557,7 +568,9 @@ function vm.eachRef(source, callback, max)
if not unlock then
return
end
- cache = eachRef(source, callback)
+ cache = {}
+ vm.cache.eachRef[source] = cache
+ eachRef(source, cache)
unlock()
for i = 1, #cache do
local src = cache[i].source