From 2cd2093b337250de8f8ece1bbebe1dbd78f95e5d Mon Sep 17 00:00:00 2001 From: number Zero Date: Sun, 28 Jan 2018 02:19:24 +0300 Subject: [PATCH] Reduce queue size --- technic/machines/switching_station.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua index 3ef9268..21d394b 100644 --- a/technic/machines/switching_station.lua +++ b/technic/machines/switching_station.lua @@ -190,9 +190,13 @@ local get_network = function(sw_pos, pos1, tier) local all_nodes = {} local queue = {} add_cable_node(all_nodes, pos1, network_id, queue) - for _, pos in ipairs(queue) do - traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, - pos, technic.machines[tier], tier, sw_pos, network_id, queue) + while next(queue) do + local to_visit = {} + for _, pos in ipairs(queue) do + traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, + pos, technic.machines[tier], tier, sw_pos, network_id, to_visit) + end + queue = to_visit end PR_nodes = flatten(PR_nodes) BA_nodes = flatten(BA_nodes)