From 96955fce58180eb5bf86d11747f7712bbefbcf62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 8 Nov 2019 17:32:43 +0800 Subject: =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/searcher/isGlobal.lua | 22 ++++++++++++++++++---- server-beta/src/searcher/searcher.lua | 1 + server-beta/test/full/example.lua | 8 ++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) (limited to 'server-beta') 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 -- cgit v1.2.3