From 6300e191ee1a36b79e70bf572614d4638df1c4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 13 Mar 2019 14:46:52 +0800 Subject: =?UTF-8?q?=E4=B8=80=E5=A4=84=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/vm/vm.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'server/src/vm/vm.lua') diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 4a54aeae..00fce559 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -8,6 +8,8 @@ local buildGlobal = require 'vm.global' local createMulti = require 'vm.multi' local libraryBuilder = require 'vm.library' +local CachedSource = setmetatable({}, { __mode = 'kv' }) + local mt = {} mt.__index = mt @@ -1075,6 +1077,7 @@ function mt:instantSource(source) if instantSource(self, source) then source:setUri(self:getUri()) self.sources[#self.sources+1] = source + CachedSource[source] = true end return source end @@ -1142,7 +1145,13 @@ function mt:isRemoved() end function mt:remove() + if self._removed then + return + end self._removed = true + for _, source in ipairs(self.sources) do + source._dead = true + end end local function compile(ast, lsp, uri) @@ -1174,5 +1183,14 @@ return function (ast, lsp, uri) if not suc then return nil, res end + local total = 0 + local alive = 0 + for source in pairs(CachedSource) do + if not source:isDead() then + alive = alive + 1 + end + total = total + 1 + end + log.debug(('CachedSource: %d/%d'):format(alive, total)) return res end -- cgit v1.2.3