From 730024055f670fef1fd4ba76b0863736a03fe227 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Mon, 16 Sep 2024 01:12:03 +0200 Subject: cache some Enum.values() call to reduce RAM allocations --- .../multi/processing/advanced/MTEAdvDistillationTower.java | 2 +- .../tileentities/machines/multi/production/MTETreeFarm.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/main/java/gtPlusPlus/xmod/gregtech') diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java index ad351caf55..a5ff70f047 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java @@ -317,7 +317,7 @@ public class MTEAdvDistillationTower extends GTPPMultiBlockBase implements ISur int tierMultiplier = getTierMultiplier(tier); List outputs = new ArrayList<>(); - for (Mode mode : Mode.values()) { + final Mode[] MODE_VALUES = Mode.values(); + for (Mode mode : MODE_VALUES) { ItemStack output = outputPerMode.get(mode); if (output == null) continue; // This sapling has no output in this mode. @@ -379,7 +380,7 @@ public class MTETreeFarm extends GTPPMultiBlockBase implements ISur duration = TICKS_PER_OPERATION; calculatedEut = GTValues.VP[tier]; - for (Mode mode : Mode.values()) { + for (Mode mode : MODE_VALUES) { if (outputPerMode.get(mode) != null) { useToolForMode(mode, true); } @@ -780,10 +781,11 @@ public class MTETreeFarm extends GTPPMultiBlockBase implements ISur * the mode multiplier, but not tool/tier multipliers as those can change dynamically. If the sapling has an * output in this mode, also add the tools usable for this mode as inputs. */ - ItemStack[][] inputStacks = new ItemStack[Mode.values().length][]; - ItemStack[] outputStacks = new ItemStack[Mode.values().length]; + final Mode[] MODE_VALUES = Mode.values(); + ItemStack[][] inputStacks = new ItemStack[MODE_VALUES.length][]; + ItemStack[] outputStacks = new ItemStack[MODE_VALUES.length]; - for (Mode mode : Mode.values()) { + for (Mode mode : MODE_VALUES) { ItemStack output = switch (mode) { case LOG -> log; case SAPLING -> saplingOut; -- cgit