Skip to content

Commit

Permalink
#1192 don't search local in simple
Browse files Browse the repository at this point in the history
use the methods provided by `local-id` to avoid wasting on `gets`
  • Loading branch information
sumneko committed Jun 7, 2022
1 parent ba6cecf commit 07bdb57
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 126 deletions.
65 changes: 0 additions & 65 deletions script/vm/def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,7 @@ local guide = require 'parser.guide'

local simpleSwitch

local function searchGetLocal(source, node, pushResult)
local key = guide.getKeyName(source)
for _, ref in ipairs(node.node.ref) do
if ref.type == 'getlocal'
and ref.next
and guide.isSet(ref.next)
and guide.getKeyName(ref.next) == key then
pushResult(ref.next)
end
end
end

simpleSwitch = util.switch()
: case 'local'
: call(function (source, pushResult)
pushResult(source)
if source.ref then
for _, ref in ipairs(source.ref) do
if ref.type == 'setlocal' then
pushResult(ref)
end
end
end
end)
: case 'sellf'
: call(function (source, pushResult)
if source.ref then
for _, ref in ipairs(source.ref) do
if ref.type == 'setlocal' then
pushResult(ref)
end
end
end
for _, res in ipairs(vm.getDefs(source.method.node)) do
pushResult(res)
end
end)
: case 'getlocal'
: case 'setlocal'
: call(function (source, pushResult)
simpleSwitch('local', source.node, pushResult)
end)
: case 'field'
: call(function (source, pushResult)
local parent = source.parent
if parent.type ~= 'tablefield' then
simpleSwitch(parent.type, parent, pushResult)
end
end)
: case 'setfield'
: case 'getfield'
: call(function (source, pushResult)
local node = source.node
if node.type == 'getlocal' then
searchGetLocal(source, node, pushResult)
return
end
end)
: case 'getindex'
: case 'setindex'
: call(function (source, pushResult)
local node = source.node
if node.type == 'getlocal' then
searchGetLocal(source, node, pushResult)
end
end)
: case 'goto'
: call(function (source, pushResult)
if source.node then
Expand Down
1 change: 1 addition & 0 deletions script/vm/local-id.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local compileSwitch = util.switch()
compileLocalID(ref)
end
end)
: case 'setlocal'
: case 'getlocal'
: call(function (source)
source._localID = ('%d'):format(source.node.start)
Expand Down
51 changes: 0 additions & 51 deletions script/vm/ref.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,7 @@ local lang = require 'language'

local simpleSwitch

local function searchGetLocal(source, node, pushResult)
local key = guide.getKeyName(source)
for _, ref in ipairs(node.node.ref) do
if ref.type == 'getlocal'
and ref.next
and guide.getKeyName(ref.next) == key then
pushResult(ref.next)
end
end
end

simpleSwitch = util.switch()
: case 'local'
: call(function (source, pushResult)
if source.ref then
for _, ref in ipairs(source.ref) do
if ref.type == 'setlocal'
or ref.type == 'getlocal' then
pushResult(ref)
end
end
end
end)
: case 'getlocal'
: case 'setlocal'
: call(function (source, pushResult)
simpleSwitch('local', source.node, pushResult)
end)
: case 'field'
: call(function (source, pushResult)
local parent = source.parent
if parent.type ~= 'tablefield' then
simpleSwitch(parent.type, parent, pushResult)
end
end)
: case 'setfield'
: case 'getfield'
: call(function (source, pushResult)
local node = source.node
if node.type == 'getlocal' then
searchGetLocal(source, node, pushResult)
return
end
end)
: case 'getindex'
: case 'setindex'
: call(function (source, pushResult)
local node = source.node
if node.type == 'getlocal' then
searchGetLocal(source, node, pushResult)
end
end)
: case 'goto'
: call(function (source, pushResult)
if source.node then
Expand Down
20 changes: 10 additions & 10 deletions test/definition/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ t.<!x!> = 1
t.<?x?>()
]]

TEST [[
local t
t[<!1!>] = 1
t[<?1?>]()
]]
--TEST [[
--local t
--t[<!1!>] = 1
--t[<?1?>]()
--]]

TEST [[
local t
t[<!true!>] = 1
t[<?true?>]()
]]
--TEST [[
--local t
--t[<!true!>] = 1
--t[<?true?>]()
--]]

TEST [[
local t
Expand Down

0 comments on commit 07bdb57

Please sign in to comment.