aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus
diff options
context:
space:
mode:
authorAlexdoru <57050655+Alexdoru@users.noreply.github.com>2024-09-16 01:12:03 +0200
committerboubou19 <miisterunknown@gmail.com>2024-09-17 22:55:46 +0200
commit730024055f670fef1fd4ba76b0863736a03fe227 (patch)
tree91ecc0fc2a99346ae7ee80ecbee2aa0d52eca6ef /src/main/java/gtPlusPlus
parentd83cc53cf944772818eb1e23c065c54accaa0034 (diff)
downloadGT5-Unofficial-730024055f670fef1fd4ba76b0863736a03fe227.tar.gz
GT5-Unofficial-730024055f670fef1fd4ba76b0863736a03fe227.tar.bz2
GT5-Unofficial-730024055f670fef1fd4ba76b0863736a03fe227.zip
cache some Enum.values() call to reduce RAM allocations
Diffstat (limited to 'src/main/java/gtPlusPlus')
-rw-r--r--src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java7
-rw-r--r--src/main/java/gtPlusPlus/xmod/forestry/bees/custom/CustomCombs.java2
-rw-r--r--src/main/java/gtPlusPlus/xmod/forestry/bees/custom/ItemCustomComb.java9
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java2
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java12
5 files changed, 17 insertions, 15 deletions
diff --git a/src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java b/src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java
index e7253b6ea5..aa79537393 100644
--- a/src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java
+++ b/src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java
@@ -103,11 +103,12 @@ public class TGSFrontend extends RecipeMapFrontend {
// Inputs
int slot = 0;
- for (int mode = 0; mode < Mode.values().length; ++mode) {
+ final Mode[] MODE_VALUES = Mode.values();
+ for (int mode = 0; mode < MODE_VALUES.length; ++mode) {
if (mode < recipe.mOreDictAlt.length && recipe.mOreDictAlt[mode] != null) {
// There is a valid input in this mode.
if (slot < neiCachedRecipe.mInputs.size() && stack == neiCachedRecipe.mInputs.get(slot).item) {
- int toolMultiplier = MTETreeFarm.getToolMultiplier(stack, Mode.values()[mode]);
+ int toolMultiplier = MTETreeFarm.getToolMultiplier(stack, MODE_VALUES[mode]);
currentTip.add(EnumChatFormatting.YELLOW + tooltipInputs[mode]);
if (toolMultiplier > 0) {
currentTip.add(EnumChatFormatting.YELLOW + tooltipMultiplier + " " + toolMultiplier + "x");
@@ -120,7 +121,7 @@ public class TGSFrontend extends RecipeMapFrontend {
// Outputs
slot = 0;
- for (int mode = 0; mode < Mode.values().length; ++mode) {
+ for (int mode = 0; mode < MODE_VALUES.length; ++mode) {
if (mode < recipe.mOutputs.length && recipe.mOutputs[mode] != null) {
// There is a valid output in this mode.
if (slot < neiCachedRecipe.mOutputs.size() && stack == neiCachedRecipe.mOutputs.get(slot).item) {
diff --git a/src/main/java/gtPlusPlus/xmod/forestry/bees/custom/CustomCombs.java b/src/main/java/gtPlusPlus/xmod/forestry/bees/custom/CustomCombs.java
index 05ab3c8711..73e01bac7a 100644
--- a/src/main/java/gtPlusPlus/xmod/forestry/bees/custom/CustomCombs.java
+++ b/src/main/java/gtPlusPlus/xmod/forestry/bees/custom/CustomCombs.java
@@ -69,7 +69,7 @@ public enum CustomCombs {
public final int chance;
private final String name;
- private CustomCombs(String pName, boolean show, Materials material, int chance) {
+ CustomCombs(String pName, boolean show, Materials material, int chance) {
this.name = pName;
this.material = material;
this.chance = chance;
diff --git a/src/main/java/gtPlusPlus/xmod/forestry/bees/custom/ItemCustomComb.java b/src/main/java/gtPlusPlus/xmod/forestry/bees/custom/ItemCustomComb.java
index 0ff3625a25..e136b825e6 100644
--- a/src/main/java/gtPlusPlus/xmod/forestry/bees/custom/ItemCustomComb.java
+++ b/src/main/java/gtPlusPlus/xmod/forestry/bees/custom/ItemCustomComb.java
@@ -82,13 +82,12 @@ public class ItemCustomComb extends Item {
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int pass) {
- int meta = Math.max(0, Math.min(CustomCombs.values().length - 1, stack.getItemDamage()));
- int colour = CustomCombs.values()[meta].getColours()[0];
-
+ final CustomCombs[] COMB_VALUES = CustomCombs.values();
+ int meta = Math.max(0, Math.min(COMB_VALUES.length - 1, stack.getItemDamage()));
+ int colour = COMB_VALUES[meta].getColours()[0];
if (pass >= 1) {
- colour = CustomCombs.values()[meta].getColours()[1];
+ colour = COMB_VALUES[meta].getColours()[1];
}
-
return colour;
}
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<MTEAdvDistillati
@Override
public void loadNBTData(NBTTagCompound aNBT) {
- mMode = Mode.values()[aNBT.getByte("mMode")];
+ mMode = Mode.VALUES[aNBT.getByte("mMode")];
mUpgraded = aNBT.getBoolean("mUpgraded");
super.loadNBTData(aNBT);
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java
index 86c4eb628f..204cd5e6b9 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java
@@ -348,7 +348,8 @@ public class MTETreeFarm extends GTPPMultiBlockBase<MTETreeFarm> implements ISur
int tierMultiplier = getTierMultiplier(tier);
List<ItemStack> 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<MTETreeFarm> 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<MTETreeFarm> 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;