change approach flush_update_queue

This commit is contained in:
alice 2024-08-17 03:03:27 +02:00 committed by centau
parent ffab944f44
commit fe9a92e336
2 changed files with 18 additions and 19 deletions

View file

@ -6,18 +6,18 @@ local graph = require(script.Parent.graph)
local function batch(setter: () -> ())
local already_batching = flags.batch
local flush
local from
if not already_batching then
flags.batch = true
flush = graph.flush_update_queue()
from = graph.get_graph_length()
end
local ok, err: string? = pcall(setter)
if not already_batching then
flags.batch = false
flush()
graph.flush_update_queue(from)
end
if not ok then throw(`error occured while batching updates: {err}`) end

View file

@ -184,27 +184,25 @@ local function queue_children_for_update<T>(node: SourceNode<T>)
update_queue.n = i
end
local function flush_update_queue()
local n0 = update_queue.n
local function get_graph_length()
return update_queue.n
end
return function()
local function flush_update_queue(from: number)
local i = from + 1
while i <= update_queue.n do
local node = update_queue[i]
--assert(node.effect)
local i = n0 + 1
while i <= update_queue.n do
local node = update_queue[i]
--assert(node.effect)
if node.owner and evaluate_node(node) then
queue_children_for_update(node)
end
update_queue[i] = false :: any
i += 1
if node.owner and evaluate_node(node) then
queue_children_for_update(node)
end
update_queue.n = n0
update_queue[i] = false :: any
i += 1
end
update_queue.n = from
end
local function update_descendants<T>(root: SourceNode<T>)
@ -284,5 +282,6 @@ return table.freeze {
create_source_node = create_source_node,
get_children = get_children,
flush_update_queue = flush_update_queue,
get_graph_length = get_graph_length,
scopes = scopes
}