From c8ca57fa703011c2dcb87d9b544e1f04809efeaa Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Thu, 18 May 2023 06:34:05 +0200 Subject: Equipment Overlay Cache (#692) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../notenoughupdates/overlays/EquipmentOverlay.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java index 4d14e47f..140c533f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java @@ -53,7 +53,9 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; @NEUAutoSubscribe @@ -150,6 +152,8 @@ public class EquipmentOverlay { public ItemStack petStack; + private Map> profileCache = new HashMap<>(); + // @SubscribeEvent public void onButtonExclusionZones(ButtonExclusionZoneEvent event) { @@ -364,6 +368,8 @@ public class EquipmentOverlay { NEUConfig.HiddenProfileSpecific profileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); if (profileSpecific == null) return null; + profileCache.putIfAbsent(lastProfile, new HashMap<>()); + Map cache = profileCache.get(lastProfile); if (isInNamedGui("Your Equipment")) { ItemStack itemStack = getChestSlotsAsItemStack(armourSlot); if (itemStack != null) { @@ -373,15 +379,21 @@ public class EquipmentOverlay { itemToSave.add("internalname", new JsonPrimitive("_")); } profileSpecific.savedEquipment.put(armourSlot, itemToSave); + cache.put(armourSlot, itemStack); return itemStack; } } else { if (profileSpecific.savedEquipment.containsKey(armourSlot)) { + if (cache.containsKey(armourSlot)) { + return cache.get(armourSlot); + } //don't use cache since the internalName is identical in most cases - JsonObject jsonObject = profileSpecific.savedEquipment - .get(armourSlot); - if (jsonObject != null) return NotEnoughUpdates.INSTANCE.manager.jsonToStack(jsonObject - .getAsJsonObject(), false); + JsonObject jsonObject = profileSpecific.savedEquipment.get(armourSlot); + if (jsonObject != null) { + ItemStack result = NotEnoughUpdates.INSTANCE.manager.jsonToStack(jsonObject.getAsJsonObject(), false); + cache.put(armourSlot, result); + return result; + } } } return null; -- cgit