diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-01-09 17:42:27 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-01-09 17:42:27 +0800 |
commit | 1ca3b7d67c0c30af1f67fae71b5c770b9008e4d5 (patch) | |
tree | 3fc65cdcca53aec16a1e03843a473ea5e9045cc3 /script/vm/tracer.lua | |
parent | c796d406329170e010590d7c9584b8483021cee3 (diff) | |
download | lua-language-server-1ca3b7d67c0c30af1f67fae71b5c770b9008e4d5.zip |
improve performance
Diffstat (limited to 'script/vm/tracer.lua')
-rw-r--r-- | script/vm/tracer.lua | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/script/vm/tracer.lua b/script/vm/tracer.lua index d4b9e5be..5aa5f63e 100644 --- a/script/vm/tracer.lua +++ b/script/vm/tracer.lua @@ -21,6 +21,7 @@ local util = require 'utility' ---@field castIndex integer? local mt = {} mt.__index = mt +mt.fastCalc = true ---@return parser.object[] function mt:getCasts() @@ -66,6 +67,21 @@ function mt:collectCare(obj) return end self.careMap[obj] = true + + if self.fastCalc then + if obj.type == 'if' + or obj.type == 'while' + or obj.type == 'binary' then + self.fastCalc = false + end + if obj.type == 'call' and obj.node then + if obj.node.special == 'assert' + or obj.node.special == 'type' then + self.fastCalc = false + end + end + end + obj = obj.parent end end @@ -104,6 +120,10 @@ function mt:collectLocal() self.casts[#self.casts+1] = cast end end + + if #self.casts > 0 then + self.fastCalc = false + end end function mt:collectGlobal() @@ -139,7 +159,7 @@ end ---@param finish integer ---@return parser.object? function mt:getLastAssign(start, finish) - local assign + local assign = self.assigns[1] for _, obj in ipairs(self.assigns) do if obj.start < start then goto CONTINUE @@ -147,7 +167,7 @@ function mt:getLastAssign(start, finish) if (obj.range or obj.start) >= finish then break end - local objBlock = guide.getParentBlock(obj) + local objBlock = guide.getTopBlock(obj) if not objBlock then break end @@ -683,6 +703,12 @@ function mt:lookIntoBlock(block, start, node) end if self.careMap[action] then node = self:lookIntoChild(action, node) + if action.type == 'do' + or action.type == 'loop' + or action.type == 'in' + or action.type == 'repeat' then + return + end end if action.finish > start and self.assignMap[action] then return @@ -690,14 +716,22 @@ function mt:lookIntoBlock(block, start, node) ::CONTINUE:: end self.nodes[block] = node + if block.type == 'do' + or block.type == 'loop' + or block.type == 'in' + or block.type == 'repeat' then + self:lookIntoBlock(block.parent, block.finish, node) + end end ---@param source parser.object function mt:calcNode(source) if self.getMap[source] then local lastAssign = self:getLastAssign(0, source.finish) - if not lastAssign then - lastAssign = source.node + assert(lastAssign) + if self.fastCalc then + self.nodes[source] = vm.compileNode(lastAssign) + return end self:calcNode(lastAssign) return |