From d40b9831c1cdcccd99a35aa1ea347b7047827c79 Mon Sep 17 00:00:00 2001 From: NotMyWing Date: Mon, 10 Jun 2024 15:40:28 +1100 Subject: [PATCH] Make craftingList a hash set in DualityInterface Improves pattern lookup times, even though I'm not sure why this check even exist --- .../java/appeng/helpers/DualityInterface.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/appeng/helpers/DualityInterface.java b/src/main/java/appeng/helpers/DualityInterface.java index 26b716cfafc..6e57f7f361c 100644 --- a/src/main/java/appeng/helpers/DualityInterface.java +++ b/src/main/java/appeng/helpers/DualityInterface.java @@ -64,7 +64,6 @@ import appeng.parts.misc.PartInterface; import appeng.tile.inventory.AppEngInternalAEInventory; import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.AppEngInternalOversizedInventory; import appeng.tile.inventory.AppEngNetworkInventory; import appeng.tile.networking.TileCableBus; import appeng.util.ConfigManager; @@ -78,6 +77,7 @@ import de.ellpeck.actuallyadditions.api.tile.IPhantomTile; import gregtech.api.block.machines.BlockMachine; import gregtech.api.metatileentity.MetaTileEntity; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Items; @@ -128,7 +128,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn private final Accessor accessor = new Accessor(); private boolean hasConfig = false; private int priority; - private List craftingList = null; + private Set craftingList = null; private List waitingToSend = null; private IMEInventory destination; private int isWorking = -1; @@ -452,10 +452,13 @@ private void updateCraftingList() { this.addToCraftingList(this.patterns.getStackInSlot(x)); } } - try { - this.gridProxy.getGrid().postEvent(new MENetworkCraftingPatternChange(this, this.gridProxy.getNode())); - } catch (GridAccessException e) { - e.printStackTrace(); + + if (newPattern || removed) { + try { + this.gridProxy.getGrid().postEvent(new MENetworkCraftingPatternChange(this, this.gridProxy.getNode())); + } catch (GridAccessException e) { + e.printStackTrace(); + } } } @@ -545,7 +548,7 @@ private void addToCraftingList(final ItemStack is) { if (details != null) { if (this.craftingList == null) { - this.craftingList = new ArrayList<>(); + this.craftingList = new ObjectOpenHashSet<>(); } this.craftingList.add(details);