优化sharetable更新 (#1208)

Co-authored-by: zixun <lb151450@alibaba-inc.com>
This commit is contained in:
子熏
2020-06-24 16:25:50 +08:00
committed by GitHub
parent 435aa384c8
commit 693176efc8

View File

@@ -258,16 +258,12 @@ local function resolve_replace(replace_map)
local function match_value(v) local function match_value(v)
assert(v ~= nil) assert(v ~= nil)
if v == RECORD then if record_map[v] or is_sharedtable(v) then
return return
end end
local tv = type(v) local tv = type(v)
local f = match[tv] local f = match[tv]
if record_map[v] or is_sharedtable(v) then
return
end
if f then if f then
record_map[v] = true record_map[v] = true
f(v) f(v)
@@ -364,7 +360,7 @@ local function resolve_replace(replace_map)
end end
local level = info.level local level = info.level
local curco = info.curco or coroutine.running() local curco = info.curco
if not level then if not level then
return return
end end
@@ -390,7 +386,7 @@ local function resolve_replace(replace_map)
end end
local stack_values_tmp = {} local stack_values_tmp = {}
local function match_thread(co) local function match_thread(co, level)
-- match stackvalues -- match stackvalues
local n = stackvalues(co, stack_values_tmp) local n = stackvalues(co, stack_values_tmp)
for i=1,n do for i=1,n do
@@ -399,40 +395,37 @@ local function resolve_replace(replace_map)
match_value(v) match_value(v)
end end
-- match callinfo level = level or 1
local level = 1
-- jump the fucntion from sharetable.update to top
local is_self = coroutine.running() == co
if is_self then
while true do
local info = getinfo(co, level, "uf")
level = level + 1
if not info then
level = 1
break
elseif info.func == sharetable.update then
break
end
end
end
while true do while true do
local info = getinfo(co, level, "uf") local info = getinfo(co, level, "uf")
if not info then if not info then
break break
end end
info.level = is_self and level + 1 or level info.level = level
info.curco = co info.curco = co
match_funcinfo(info) match_funcinfo(info)
level = level + 1 level = level + 1
end end
end end
local function prepare_match()
local co = coroutine.running()
record_map[co] = true
record_map[match] = true
record_map[RECORD] = true
record_map[record_map] = true
record_map[insert_replace] = true
record_map[resolve_replace] = true
assert(getinfo(co, 3, "f").func == sharetable.update)
match_thread(co, 5) -- ignore match_thread and match_funcinfo frame
end
match["table"] = match_table match["table"] = match_table
match["function"] = match_function match["function"] = match_function
match["userdata"] = match_userdata match["userdata"] = match_userdata
match["thread"] = match_thread match["thread"] = match_thread
prepare_match()
match_internmt() match_internmt()
local root = debug.getregistry() local root = debug.getregistry()