From 2a3abcc6b8859b11e13c9d95d7426590edf9fefd Mon Sep 17 00:00:00 2001 From: tth05 <36999320+tth05@users.noreply.github.com> Date: Sat, 20 Jan 2024 23:00:50 +0100 Subject: Remove all usages of GT_ItemStack2 as Set/Map keys by using fastutil (#2465) * Replace Maps in GT_OreDictUnificator with fastutil implementations with custom hasher Removes the need to allocate a GT_ItemStack2 every time these Maps are accessed * Replace local HashMaps with Reference2LongArrayMaps in GT_Recipe and fix if condition * Remove GT_ItemStack2 usage from OrePrefixes * Update GTNHLib requirement in @Mod annotation * Don't modify stack argument when re-trying `setItemStack2DataMap` access with wildcard value --- src/main/java/gregtech/api/util/GT_Recipe.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/main/java/gregtech/api/util/GT_Recipe.java') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index a7c6c654e7..b06c7f9e64 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -36,6 +36,8 @@ import gregtech.api.recipe.metadata.IRecipeMetadataStorage; import gregtech.api.util.extensions.ArrayExt; import gregtech.api.util.item.ItemHolder; import ic2.core.Ic2Items; +import it.unimi.dsi.fastutil.objects.Reference2LongArrayMap; +import it.unimi.dsi.fastutil.objects.Reference2LongMap; public class GT_Recipe implements Comparable { @@ -486,25 +488,27 @@ public class GT_Recipe implements Comparable { double currentParallel = maxParallel; - if (aFluidInputs != null) { + // We need to have any fluids inputs, otherwise the code below does nothing. The second check is always true + // because of early exit condition above. + if (mFluidInputs.length > 0 /* && aFluidInputs != null */) { // Create map for fluid -> stored amount - Map fluidMap = new HashMap<>(); - Map fluidCost = new HashMap<>(); + Reference2LongMap fluidMap = new Reference2LongArrayMap<>(4); + Reference2LongMap fluidCost = new Reference2LongArrayMap<>(4); for (FluidStack fluidStack : aFluidInputs) { if (fluidStack == null) continue; - fluidMap.merge(fluidStack.getFluid(), (long) fluidStack.amount, Long::sum); + fluidMap.mergeLong(fluidStack.getFluid(), fluidStack.amount, Long::sum); } for (FluidStack fluidStack : mFluidInputs) { if (fluidStack == null) continue; - fluidCost.merge(fluidStack.getFluid(), (long) fluidStack.amount, Long::sum); + fluidCost.mergeLong(fluidStack.getFluid(), fluidStack.amount, Long::sum); } // Check how many parallels can it perform for each fluid - for (Map.Entry costEntry : fluidCost.entrySet()) { - if (costEntry.getValue() > 0) { + for (Reference2LongMap.Entry costEntry : fluidCost.reference2LongEntrySet()) { + if (costEntry.getLongValue() > 0) { currentParallel = Math.min( currentParallel, - (double) fluidMap.getOrDefault(costEntry.getKey(), 0L) / costEntry.getValue()); + (double) fluidMap.getOrDefault(costEntry.getKey(), 0L) / costEntry.getLongValue()); } if (currentParallel <= 0) { return 0; -- cgit