diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-10 19:27:19 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-10 19:27:19 +0800 |
commit | 0d1a38eb45e67c5e724cba354ca673344d69b4e9 (patch) | |
tree | 3a1b0c030a0e66ad4a7ab37f4c6755f9ef513f55 /server-beta/src | |
parent | 65e612667dbe0c9529b9a318871f5807754be64d (diff) | |
download | lua-language-server-0d1a38eb45e67c5e724cba354ca673344d69b4e9.zip |
优化全局变量性能
Diffstat (limited to 'server-beta/src')
-rw-r--r-- | server-beta/src/searcher/eachGlobal.lua | 1 | ||||
-rw-r--r-- | server-beta/src/searcher/getLibrary.lua | 29 | ||||
-rw-r--r-- | server-beta/src/searcher/isGlobal.lua | 28 |
3 files changed, 9 insertions, 49 deletions
diff --git a/server-beta/src/searcher/eachGlobal.lua b/server-beta/src/searcher/eachGlobal.lua index 8f556976..27ee0f21 100644 --- a/server-beta/src/searcher/eachGlobal.lua +++ b/server-beta/src/searcher/eachGlobal.lua @@ -21,6 +21,7 @@ local function eachGlobal(source, callback) end result[name][#result[name]+1] = info result[name].mode[info.mode] = true + searcher.cache.isGlobal[src] = true end) for _, info in pairs(result) do callback(info) diff --git a/server-beta/src/searcher/getLibrary.lua b/server-beta/src/searcher/getLibrary.lua index 3b9714a3..062c8937 100644 --- a/server-beta/src/searcher/getLibrary.lua +++ b/server-beta/src/searcher/getLibrary.lua @@ -5,39 +5,16 @@ local library = require 'library' local function getLibrary(source) local name = guide.getKeyName(source) if not name then - return + return nil end local sname = name:match '^s|(.+)$' if not sname then - return + return nil end if searcher.isGlobal(source) then return library.global[sname] end - local node = source.node - if not node then - return - end - - local lib - searcher.eachRef(node, function (info) - local src = info.source - if info.mode == 'get' and searcher.isGlobal(node) then - local nodeName = guide.getKeyName(src) - if not nodeName then - return - end - local sNodeName = nodeName:match '^s|(.+)$' - if not sNodeName then - return - end - local tbl = library.global[sNodeName] - if tbl then - lib = lib or tbl[sname] - end - end - end) - return lib + return nil end function searcher.getLibrary(source) diff --git a/server-beta/src/searcher/isGlobal.lua b/server-beta/src/searcher/isGlobal.lua index 72a9448b..e4093b58 100644 --- a/server-beta/src/searcher/isGlobal.lua +++ b/server-beta/src/searcher/isGlobal.lua @@ -1,28 +1,10 @@ local searcher = require 'searcher.searcher' - -local function isGlobal(source) - local node = source.node - if not node then - return false - end - local global = searcher.eachRef(node, function (info) - if info.source.tag == '_ENV' then - return true - end - end) - return global or false -end +local guide = require 'parser.guide' function searcher.isGlobal(source) - local cache = searcher.cache.isGlobal[source] - if cache ~= nil then - return cache + source = guide.getRoot(source) + if not searcher.cache.eachGlobal[source] then + searcher.eachGlobal(source, function () end) 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 + return searcher.cache.isGlobal[source] == true end |