diff options
-rw-r--r-- | server-beta/src/searcher/isGlobal.lua | 22 | ||||
-rw-r--r-- | server-beta/src/searcher/searcher.lua | 1 | ||||
-rw-r--r-- | server-beta/test/full/example.lua | 8 |
3 files changed, 25 insertions, 6 deletions
diff --git a/server-beta/src/searcher/isGlobal.lua b/server-beta/src/searcher/isGlobal.lua index 549220a9..d59a6876 100644 --- a/server-beta/src/searcher/isGlobal.lua +++ b/server-beta/src/searcher/isGlobal.lua @@ -1,15 +1,29 @@ local searcher = require 'searcher.searcher' -function searcher.isGlobal(source) +local function isGlobal(source) local node = source.node if not node then return false end - local isGlobal + local global searcher.eachRef(node, function (info) if info.source.tag == '_ENV' then - isGlobal = true + global = true end end) - return isGlobal + return global +end + +function searcher.isGlobal(source) + local cache = searcher.cache.isGlobal[source] + if cache ~= nil then + return cache + end + cache = isGlobal(source) + searcher.cache.isGlobal[source] = cache + searcher.eachRef(source, function (info) + local src = info.source + searcher.cache.isGlobal[src] = cache + end) + return cache end diff --git a/server-beta/src/searcher/searcher.lua b/server-beta/src/searcher/searcher.lua index 059afe8a..a5b2d677 100644 --- a/server-beta/src/searcher/searcher.lua +++ b/server-beta/src/searcher/searcher.lua @@ -108,6 +108,7 @@ function m.refreshCache() eachRef = {}, eachField = {}, eachGlobal = {}, + isGlobal = {}, specialName = {}, getLibrary = {}, specials = nil, diff --git a/server-beta/test/full/example.lua b/server-beta/test/full/example.lua index 670bfe64..5b096655 100644 --- a/server-beta/test/full/example.lua +++ b/server-beta/test/full/example.lua @@ -1,5 +1,7 @@ -local util = require 'utility' +local util = require 'utility' local parser = require 'parser' +local files = require 'files' +local diag = require 'core.diagnostics' -- 临时 local function testIfExit(path) @@ -25,7 +27,9 @@ local function testIfExit(path) local need local lines = parser:lines(buf) for i = 1, max do - --core.diagnostics(vm, lines, 'test') + files.removeAll() + files.setText('', buf) + diag('') local passed = os.clock() - clock if passed >= 1.0 or i == max then need = passed / i |