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/enums/OrePrefixes.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/main/java/gregtech/api/enums') diff --git a/src/main/java/gregtech/api/enums/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java index e9294e7258..26dee844e7 100644 --- a/src/main/java/gregtech/api/enums/OrePrefixes.java +++ b/src/main/java/gregtech/api/enums/OrePrefixes.java @@ -20,13 +20,14 @@ import gregtech.api.interfaces.ICondition; import gregtech.api.interfaces.IOreRecipeRegistrator; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.objects.GT_ArrayList; -import gregtech.api.objects.GT_HashSet; -import gregtech.api.objects.GT_ItemStack2; +import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.objects.MaterialStack; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_Utility; import gregtech.loaders.materialprocessing.ProcessingModSupport; +import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; +import it.unimi.dsi.fastutil.objects.ObjectSet; public enum OrePrefixes { @@ -1015,7 +1016,10 @@ public enum OrePrefixes { public MaterialStack mSecondaryMaterial = null; public OrePrefixes mPrefixInto = this; public float mHeatDamage = 0.0F; // Negative for Frost Damage - private final GT_HashSet mContainsTestCache = new GT_HashSet<>(512, 0.5f); + private final ObjectSet mContainsTestCache = new ObjectOpenCustomHashSet<>( + 512, + 0.5f, + GT_ItemStack.ITEMSTACK_HASH_STRATEGY2); public static final List mPreventableComponents = new LinkedList<>( Arrays.asList( OrePrefixes.gem, @@ -1205,13 +1209,13 @@ public enum OrePrefixes { if (!contains(aStack)) { mPrefixedItems.add(aStack); // It's now in there... so update the cache - mContainsTestCache.add(new GT_ItemStack2(aStack)); + mContainsTestCache.add(aStack); } return true; } public boolean contains(ItemStack aStack) { - return !GT_Utility.isStackInvalid(aStack) && mContainsTestCache.contains(new GT_ItemStack2(aStack)); + return !GT_Utility.isStackInvalid(aStack) && mContainsTestCache.contains(aStack); } public boolean containsUnCached(ItemStack aStack) { -- cgit