diff options
author | tth05 <36999320+tth05@users.noreply.github.com> | 2024-01-20 23:00:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-20 23:00:50 +0100 |
commit | 2a3abcc6b8859b11e13c9d95d7426590edf9fefd (patch) | |
tree | 96b9ba00d09a0390e537abfa47969a1824f7ac9b /src/main/java/gregtech/api/util/GT_Recipe.java | |
parent | 8aedb43274634bb4df44b67da7a7fe98a33ecf55 (diff) | |
download | GT5-Unofficial-2a3abcc6b8859b11e13c9d95d7426590edf9fefd.tar.gz GT5-Unofficial-2a3abcc6b8859b11e13c9d95d7426590edf9fefd.tar.bz2 GT5-Unofficial-2a3abcc6b8859b11e13c9d95d7426590edf9fefd.zip |
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
Diffstat (limited to 'src/main/java/gregtech/api/util/GT_Recipe.java')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_Recipe.java | 20 |
1 files changed, 12 insertions, 8 deletions
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<GT_Recipe> { @@ -486,25 +488,27 @@ public class GT_Recipe implements Comparable<GT_Recipe> { 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<Fluid, Long> fluidMap = new HashMap<>(); - Map<Fluid, Long> fluidCost = new HashMap<>(); + Reference2LongMap<Fluid> fluidMap = new Reference2LongArrayMap<>(4); + Reference2LongMap<Fluid> 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<Fluid, Long> costEntry : fluidCost.entrySet()) { - if (costEntry.getValue() > 0) { + for (Reference2LongMap.Entry<Fluid> 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; |