summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorunknown <sumnekosun@intranet.123u.com>2019-04-02 17:56:07 +0800
committerunknown <sumnekosun@intranet.123u.com>2019-04-02 17:56:07 +0800
commita006de81d0c4c6e97580d5d8ac9dc7a0cb2b5945 (patch)
tree6b6bca26b4b98d2d691619df42f53137ab9e9944 /server
parenteb90f54d5bef871070b45cae9863c779755faf04 (diff)
downloadlua-language-server-a006de81d0c4c6e97580d5d8ac9dc7a0cb2b5945.zip
每次合并都清理child
Diffstat (limited to 'server')
-rw-r--r--server/src/vm/value.lua58
1 files changed, 33 insertions, 25 deletions
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index 84ee4444..73c47cb0 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -191,30 +191,44 @@ function mt:getMetaMethod(name)
return meta:rawGet(name)
end
-function mt:rawEach(callback, mark)
+function mt:flushChild(child)
if not self._child then
return nil
end
- local alived
-- 非全局值不会出现dead child
- if self._global then
- alived = {}
- local infos = self._info
- local count = 0
- for srcId, info in pairs(infos) do
- local src = listMgr.get(srcId)
- if src
- and (info.type == 'set child' or info.type == 'get child')
- then
- alived[info[1]] = true
- count = count + 1
- else
- infos[srcId] = nil
- end
+ if not self._global then
+ return
+ end
+ local alived = {}
+ local infos = self._info
+ local count = 0
+ for srcId, info in pairs(infos) do
+ local src = listMgr.get(srcId)
+ if src
+ and (info.type == 'set child' or info.type == 'get child')
+ then
+ alived[info[1]] = true
+ count = count + 1
+ else
+ infos[srcId] = nil
end
- infos._count = count
- infos._limit = count + 10
end
+ infos._count = count
+ infos._limit = count + 10
+ for index in pairs(self._child) do
+ if not alived[index] then
+ self._child[index] = nil
+ goto CONTINUE
+ end
+ ::CONTINUE::
+ end
+end
+
+function mt:rawEach(callback, mark)
+ if not self._child then
+ return nil
+ end
+ self:flushChild()
for index, value in pairs(self._child) do
if mark then
if mark[index] then
@@ -222,10 +236,6 @@ function mt:rawEach(callback, mark)
end
mark[index] = true
end
- if alived and not alived[index] then
- self._child[index] = nil
- goto CONTINUE
- end
local res = callback(index, value)
if res ~= nil then
return res
@@ -281,9 +291,6 @@ function mt:mergeValue(value)
end
value._type = self._type
- -- TODO: 这里有一处泄漏:value 的 child 只在 eachChild 与 rawEach 时清理
- -- 而 child 的 key 有可能是对象,反复合并会导致 child 越来越大
- -- 目前只有 function:mergeReturn 会调用 mergeValue ,因此表现不明显
if value._child then
if not self._child then
self._child = {}
@@ -293,6 +300,7 @@ function mt:mergeValue(value)
end
end
value._child = self._child
+ self:flushChild()
local infos = self._info
for srcId, info in pairs(value._info) do