Update exportTask.lua

So uhh, yeah, the looped getItemMeta calls cost me a LOT of time. Figured out most of the relevant data I wanted was already being provided elsewhere, no extra calls to make, it's as fast as I can make it now. Now it's dependent on the storage optimizations as they stand, this does not speed anything up, just makes it more accurate.
This commit is contained in:
cynagen
2020-05-18 03:09:55 -07:00
committed by GitHub
parent 995ca9d486
commit 2873401782

View File

@@ -66,11 +66,12 @@ function ExportTask:cycle(context)
end
local function exportItems()
node.cacheList = node.adapter.list()
local cache,size={node.adapter.list(),node.adapter.size()} -- Make single calls, not repeat
local cacheSize=Util.size(cache) -- Same, though this call doesn't hurt as bad
for key in pairs(entry.filter) do
local items = Milo:getMatches(itemDB:splitKey(key), entry)
for _,item in pairs(items) do
if node.adapter.size() ~= Util.size(node.cacheList) then
if size ~= cacheSize then
-- Here we have a storage which has at least 1 unpopulated slot, we can fire'n'forget into this
if context.storage:export(node, nil, item.count, item) == 0 then
-- TODO: really shouldn't break here as there may be room in other slots
@@ -79,19 +80,21 @@ function ExportTask:cycle(context)
end
else
-- Here we have a storage with all slots occupied, sort through and find open spaces
for iNum,_ in ipairs(node.cacheList) do
local slot = node.adapter.getItemMeta(iNum)
if (slot.name == filterItem.name and slot.count ~= slot.maxCount and
(entry.ignoreDamage or slot.damage == filterItem.damage) and
(entry.ignoreNbtHash or slot.nbtHash == filterItem.nbtHash)) then
-- We found a slot that matches, and is not full, let's export to it!
context.storage:export(node, iNum, math.min(slot.maxCount-slot.count,item.count), item)
for iNum=1,size do
local slot = cache[i]
if slot then
if (slot.name == item.name and slot.count ~= item.maxCount and
(entry.ignoreDamage or slot.damage == item.damage) and
(entry.ignoreNbtHash or slot.nbtHash == item.nbtHash)) then
-- We found a slot that matches, and is not full, let's export to it!
-- Reworked to use item's .maxCount against the existing .list()[slot].count instead of repeat .getItemMeta calls
context.storage:export(node, iNum, math.min(item.maxCount-slot.count,item.count), item)
end
end
end
end
end
end
node.cacheList=nil
end
if type(entry.slot) == 'number' then
exportSingleSlot()