summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/noder.lua12
-rw-r--r--script/core/searcher.lua2
-rw-r--r--script/vm/vm.lua10
3 files changed, 7 insertions, 17 deletions
diff --git a/script/core/noder.lua b/script/core/noder.lua
index 2ef34e80..89be1e62 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -3,8 +3,6 @@ local guide = require 'parser.guide'
local collector = require 'core.collector'
local files = require 'files'
-local LastIDCache = {}
-local FirstIDCache = {}
local SPLIT_CHAR = '\x1F'
local LAST_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']*$'
local FIRST_REGEX = '^[^' .. SPLIT_CHAR .. ']*'
@@ -972,15 +970,10 @@ end
---@param id string
---@return string
function m.getFirstID(id)
- if FirstIDCache[id] then
- return FirstIDCache[id] or nil
- end
local firstID, count = id:match(FIRST_REGEX)
if count == 0 then
- FirstIDCache[id] = false
return nil
end
- FirstIDCache[id] = firstID
return firstID
end
@@ -988,15 +981,10 @@ end
---@param id string
---@return string
function m.getLastID(id)
- if LastIDCache[id] then
- return LastIDCache[id] or nil
- end
local lastID, count = id:gsub(LAST_REGEX, '')
if count == 0 then
- LastIDCache[id] = false
return nil
end
- LastIDCache[id] = lastID
return lastID
end
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 75176961..ee8af71a 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -200,7 +200,7 @@ local function crossSearch(status, uri, expect, mode, sourceUri)
end
local function checkCache(status, uri, expect, mode)
- local cache = vm.getCache('search:' .. mode)
+ local cache = vm.getCache('search:' .. mode, true)
local fileCache = cache[uri]
if not fileCache then
fileCache = {}
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