diff options
author | sumneko <sumneko@hotmail.com> | 2019-05-08 15:31:02 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-05-08 15:31:02 +0800 |
commit | 04d1af4aa0b26e7ddc28a5d8c056b23097c9175b (patch) | |
tree | 0d6c5a8d97d30ceebc0da93365051215baba80b9 /server/src | |
parent | 3021033d1b11e916c93cfe78dcc9056366837ff6 (diff) | |
download | lua-language-server-04d1af4aa0b26e7ddc28a5d8c056b23097c9175b.zip |
找100个dead value
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/service.lua | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/server/src/service.lua b/server/src/service.lua index 81b5b98e..3501b39a 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -826,7 +826,54 @@ function mt:_testMemory() )) log.debug('test memory: ', ('%.3f'):format(os.clock() - clock)) - --self:_testDeadValue() + if deadValue / totalValue >= 0.1 then + self:_testFindDeadValues() + end +end + +function mt:_testFindDeadValues() + if self._testHasFoundDeadValues then + return + end + self._testHasFoundDeadValues = true + + local mark = {} + local stack = {} + local count = 0 + local function push(info) + stack[#stack+1] = info + end + local function pop() + stack[#stack] = nil + end + local function showStack() + count = count + 1 + log.debug(table.concat(stack, '->')) + end + local function scan(name, tbl) + if count > 100 then + return + end + if type(tbl) ~= 'table' then + return + end + if mark[tbl] then + return + end + mark[tbl] = true + push(name) + if tbl.type == 'value' then + if not tbl:getSource() then + showStack() + end + else + for k, v in pairs(tbl) do + scan(k, v) + end + end + pop() + end + scan('root', self._file) end function mt:onTick() |