summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-06-18 19:48:11 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-06-18 19:48:11 +0800
commit2c461c6fc0a46b9ef44293dc9d8524b60d5c1f75 (patch)
tree0092508b2a9244d6a876d2f4cb3a5b124aefeb20 /script/vm
parent78e9c078f77fce1f7d6816a0904e38f45a0164e4 (diff)
downloadlua-language-server-2c461c6fc0a46b9ef44293dc9d8524b60d5c1f75.zip
no more ID cache
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/vm.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/script/vm/vm.lua b/script/vm/vm.lua
index 0e7f3176..a9c788fc 100644
--- a/script/vm/vm.lua
+++ b/script/vm/vm.lua
@@ -10,6 +10,8 @@ local log = log
local xpcall = xpcall
local mathHuge = math.huge
+local weakValueMT = { __mode = 'v' }
+
_ENV = nil
---@class vm
@@ -104,7 +106,7 @@ function m.mergeResults(a, b)
return a
end
-m.cacheTracker = setmetatable({}, { __mode = 'kv' })
+m.cacheTracker = setmetatable({}, weakValueMT)
function m.flushCache()
if m.cache then
@@ -113,17 +115,17 @@ function m.flushCache()
m.cacheVersion = files.globalVersion
m.cache = {}
m.cacheActiveTime = mathHuge
- m.locked = setmetatable({}, { __mode = 'k' })
+ m.locked = setmetatable({}, weakValueMT)
m.cacheTracker[m.cache] = true
end
-function m.getCache(name)
+function m.getCache(name, weak)
if m.cacheVersion ~= files.globalVersion then
m.flushCache()
end
m.cacheActiveTime = timer.clock()
if not m.cache[name] then
- m.cache[name] = {}
+ m.cache[name] = weak and setmetatable({}, weakValueMT) or {}
end
return m.cache[name]
end