diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-05 20:55:25 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-05 20:55:25 +0800 |
commit | 6f927f4fa9a7c6e0446755a3f6aa86570c684754 (patch) | |
tree | ff86afad2f404c8df68233767fcbbe3d626acabd /script-beta/vm/getGlobals.lua | |
parent | fe6f1115b5302ddd8ea7ed3e61a222d7294454d0 (diff) | |
download | lua-language-server-6f927f4fa9a7c6e0446755a3f6aa86570c684754.zip |
优化有大量全局变量时的性能
Diffstat (limited to 'script-beta/vm/getGlobals.lua')
-rw-r--r-- | script-beta/vm/getGlobals.lua | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua index 7b42d345..380a21ac 100644 --- a/script-beta/vm/getGlobals.lua +++ b/script-beta/vm/getGlobals.lua @@ -90,24 +90,15 @@ local function insertLibrary(results, name) end end -local function getGlobals(name, fast) +local function getGlobals(name) local results = {} - local mark = {} for uri in files.eachFile() do local cache = files.getCache(uri) cache.globals = cache.globals or getGlobalsOfFile(uri) if name == '*' then - for destName, sources in util.sortPairs(cache.globals) do - if not fast or not mark[destName] then - if fast then - mark[destName] = true - end - for _, source in ipairs(sources) do - results[#results+1] = source - if fast then - break - end - end + for _, sources in util.sortPairs(cache.globals) do + for _, source in ipairs(sources) do + results[#results+1] = source end end else @@ -122,15 +113,33 @@ local function getGlobals(name, fast) return results end -function vm.getGlobals(name, fast) +local function getAnyGlobalsFast() + local results = {} + local mark = {} + for uri in files.eachFile() do + local cache = files.getCache(uri) + cache.globals = cache.globals or getGlobalsOfFile(uri) + for destName, sources in util.sortPairs(cache.globals) do + if not mark[destName] then + mark[destName] = true + results[#results+1] = sources[1] + end + end + end + insertLibrary(results, '*') + return results +end + +function vm.getGlobals(name) + if name == '*' and config.config.intelliSense.fastGlobal then + return getAnyGlobalsFast() + end local cache = vm.getCache('getGlobals')[name] if cache ~= nil then return cache end - cache = getGlobals(name, fast) - if not fast then - vm.getCache('getGlobals')[name] = cache - end + cache = getGlobals(name) + vm.getCache('getGlobals')[name] = cache return cache end |