From 177e45bdd83fe923ffc85205e19f071b6bc8f464 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 14 Feb 2013 12:49:57 +0400 Subject: [PATCH] Improve fix/cloth-stockpile performance by 30% by reducing garbage. --- scripts/fix/cloth-stockpile.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/fix/cloth-stockpile.lua b/scripts/fix/cloth-stockpile.lua index 7da5d583c..45e5fcc43 100644 --- a/scripts/fix/cloth-stockpile.lua +++ b/scripts/fix/cloth-stockpile.lua @@ -1,8 +1,16 @@ -- Fixes cloth/thread stockpiles by correcting material object data. local raws = df.global.world.raws -local organic_types = raws.mat_table.organic_types -local organic_indexes = raws.mat_table.organic_indexes + +-- Cache references to vectors in lua tables for a speed-up +local organic_types = {} +for i,v in ipairs(raws.mat_table.organic_types) do + organic_types[i] = v +end +local organic_indexes = {} +for i,v in ipairs(raws.mat_table.organic_indexes) do + organic_indexes[i] = v +end local function verify(category,idx,vtype,vidx) if idx == -1 then