From 57d3a145417242d1c733219013490543baca26c5 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 30 Apr 2023 23:43:37 +0200 Subject: Removed neu item caches that caused memory leaks --- .../java/at/hannibal2/skyhanni/utils/NEUItems.kt | 37 ++++++---------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index f24ea4949..2437174c3 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -18,8 +18,6 @@ import net.minecraft.nbt.NBTTagCompound object NEUItems { val manager: NEUManager get() = NotEnoughUpdates.INSTANCE.manager - private val itemIdCache = mutableMapOf() // stack -> internal name - private val idItemCache = mutableMapOf() // internal name -> stack private val itemNameCache = mutableMapOf() // item name -> internal name private val multiplierCache = mutableMapOf>() private val recipesCache = mutableMapOf>() @@ -57,22 +55,13 @@ object NEUItems { return text } - fun getInternalName(itemStack: ItemStack): String { - if (itemIdCache.containsKey(itemStack)) { - return itemIdCache[itemStack]!! - } - - val internalId = ItemResolutionQuery(manager) - .withCurrentGuiContext() - .withItemStack(itemStack) - .resolveInternalName() ?: "" - itemIdCache[itemStack] = internalId - return internalId - } + fun getInternalName(itemStack: ItemStack) = ItemResolutionQuery(manager) + .withCurrentGuiContext() + .withItemStack(itemStack) + .resolveInternalName() ?: "" - fun getInternalNameOrNull(nbt: NBTTagCompound): String? { - return ItemResolutionQuery(manager).withItemNBT(nbt).resolveInternalName() - } + fun getInternalNameOrNull(nbt: NBTTagCompound) = + ItemResolutionQuery(manager).withItemNBT(nbt).resolveInternalName() fun getPriceOrNull(internalName: String, useSellingPrice: Boolean = false): Double? { val price = getPrice(internalName, useSellingPrice) @@ -103,17 +92,9 @@ object NEUItems { return result } - fun getItemStackOrNull(internalName: String): ItemStack? { - if (idItemCache.contains(internalName)) { - return idItemCache[internalName]!!.copy() - } - - val itemStack = ItemResolutionQuery(manager) - .withKnownInternalName(internalName) - .resolveToItemStack() ?: return null - idItemCache[internalName] = itemStack - return itemStack.copy() - } + fun getItemStackOrNull(internalName: String) = ItemResolutionQuery(manager) + .withKnownInternalName(internalName) + .resolveToItemStack()?.copy() fun getItemStack(internalName: String): ItemStack { val stack = getItemStackOrNull(internalName) -- cgit