From df80f18f908fa4a99b965f5170b03248cf364802 Mon Sep 17 00:00:00 2001 From: kilbith Date: Mon, 24 Aug 2015 21:44:39 +0200 Subject: [PATCH] Optimize table inserting --- worktable.lua | 4 ++-- xwall.lua | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/worktable.lua b/worktable.lua index 34573e1..9b50256 100644 --- a/worktable.lua +++ b/worktable.lua @@ -98,7 +98,7 @@ function worktable.dig(pos, _) if not inv:is_empty("input") or not inv:is_empty("forms") or not inv:is_empty("hammer") or not inv:is_empty("tool") or not - inv:is_empty("storage") or not inv:is_empty("craft") then + inv:is_empty("storage") then return false end return true @@ -146,7 +146,7 @@ local function update_form_inventory(inv, input_stack) local form_name = form[1] local count = math.min(worktable.anz(form_name) * inv:get_stack("input", 1):get_count(), input_stack:get_stack_max()) - table.insert(form_inv_list, string.format("xdecor:%s_%s %d", form_name, material_name, count)) + form_inv_list[#form_inv_list+1] = string.format("xdecor:%s_%s %d", form_name, material_name, count) end inv:set_list("forms", form_inv_list) end diff --git a/xwall.lua b/xwall.lua index fd74198..3cc5932 100644 --- a/xwall.lua +++ b/xwall.lua @@ -104,33 +104,33 @@ function xwall.construct_node_box_data(node_box_list, center_node_box_list, node res.c0, res.c1, res.c2, res.c3, res.c4 = {}, {}, {}, {}, {} for _, v in pairs(node_box_list) do - table.insert(res.c1, v) - table.insert(res.c2, v) - table.insert(res.c3, v) - table.insert(res.c4, v) + res.c1[#res.c1+1] = v + res.c2[#res.c2+1] = v + res.c3[#res.c3+1] = v + res.c4[#res.c4+1] = v end for _, v in pairs(node_box_list) do - table.insert(res.c2, {v[3], v[2], v[1], v[6], v[5], v[4]}) - table.insert(res.c3, {v[3], v[2], v[1], v[6], v[5], v[4]}) - table.insert(res.c4, {v[3], v[2], v[1], v[6], v[5], v[4]}) + res.c2[#res.c2+1] = {v[3], v[2], v[1], v[6], v[5], v[4]} + res.c3[#res.c3+1] = {v[3], v[2], v[1], v[6], v[5], v[4]} + res.c4[#res.c4+1] = {v[3], v[2], v[1], v[6], v[5], v[4]} end for _, v in pairs(node_box_list) do - table.insert(res.c3, {v[4], v[2], v[3]-0.5, v[1], v[5], v[6]-0.5}) - table.insert(res.c4, {v[4], v[2], v[3]-0.5, v[1], v[5], v[6]-0.5}) + res.c3[#res.c3+1] = {v[4], v[2], v[3]-0.5, v[1], v[5], v[6]-0.5} + res.c4[#res.c4+1] = {v[4], v[2], v[3]-0.5, v[1], v[5], v[6]-0.5} end for _, v in pairs(node_box_list) do - table.insert(res.c4, {v[3]-0.5, v[2], v[4], v[6]-0.5, v[5], v[1]}) + res.c4[#res.c4+1] = {v[3]-0.5, v[2], v[4], v[6]-0.5, v[5], v[1]} end for _, v in pairs(center_node_box_list) do - table.insert(res.c0, v) - table.insert(res.c1, v) - table.insert(res.c2, v) - table.insert(res.c3, v) - table.insert(res.c4, v) + res.c0[#res.c0+1] = v + res.c1[#res.c1+1] = v + res.c2[#res.c2+1] = v + res.c3[#res.c3+1] = v + res.c4[#res.c4+1] = v end if #res.c0 < 1 then res.c0 = nil end