diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-21 20:52:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-21 20:52:05 +0800 |
commit | ca322946af06afa7bfd93fa176812ceed854730e (patch) | |
tree | e32e54acea059359a27ecf35c9ab305d8a5e0f51 /script-beta/vm/getClass.lua | |
parent | 0bb3565ed9e8f3fb0d9501f7ac2b3c7aa0245a86 (diff) | |
download | lua-language-server-ca322946af06afa7bfd93fa176812ceed854730e.zip |
优化性能
Diffstat (limited to 'script-beta/vm/getClass.lua')
-rw-r--r-- | script-beta/vm/getClass.lua | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/script-beta/vm/getClass.lua b/script-beta/vm/getClass.lua index 03cde93a..522ca026 100644 --- a/script-beta/vm/getClass.lua +++ b/script-beta/vm/getClass.lua @@ -1,8 +1,8 @@ local vm = require 'vm.vm' local guide = require 'parser.guide' -local function getClass(source, classes, deep) - local lib = vm.getLibrary(source) +local function getClass(source, classes, deep, simple) + local lib = vm.getLibrary(source, simple) if lib then if lib.value.type == 'table' then classes[#classes+1] = lib.value.name @@ -15,33 +15,39 @@ local function getClass(source, classes, deep) return end local value = guide.getObjectValue(source) or source - vm.eachField(value, function (src) - local key = vm.getKeyName(src) - if not key then - return + if simple and value == source then + if value and value.type == 'string' then + classes[#classes+1] = value[1] end - local lkey = key:lower() - if lkey == 's|type' - or lkey == 's|__name' - or lkey == 's|name' - or lkey == 's|class' then - local value = guide.getObjectValue(src) - if value and value.type == 'string' then - classes[#classes+1] = value[1] + else + vm.eachField(value, function (src) + local key = vm.getKeyName(src) + if not key then + return end - end - end) + local lkey = key:lower() + if lkey == 's|type' + or lkey == 's|__name' + or lkey == 's|name' + or lkey == 's|class' then + local value = guide.getObjectValue(src) + if value and value.type == 'string' then + classes[#classes+1] = value[1] + end + end + end) + end if #classes ~= 0 then return end vm.eachMeta(source, function (mt) - getClass(mt, classes, deep + 1) + getClass(mt, classes, deep + 1, simple) end) end -function vm.getClass(source) +function vm.getClass(source, simple) local classes = {} - getClass(source, classes, 1) + getClass(source, classes, 1, simple) if #classes == 0 then return nil end |