From 9518818a10c00ba60fb105dd2a7313fbbd1fe492 Mon Sep 17 00:00:00 2001 From: Kli Kli Date: Sat, 30 Dec 2023 16:10:37 +0100 Subject: [PATCH] feat: cache storage actuator search results for better performance Closes #1021 --- .../client/gui/storage/StorageControllerGuiBase.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/klikli_dev/occultism/client/gui/storage/StorageControllerGuiBase.java b/src/main/java/com/klikli_dev/occultism/client/gui/storage/StorageControllerGuiBase.java index 9c18f9b11..750984075 100644 --- a/src/main/java/com/klikli_dev/occultism/client/gui/storage/StorageControllerGuiBase.java +++ b/src/main/java/com/klikli_dev/occultism/client/gui/storage/StorageControllerGuiBase.java @@ -102,6 +102,9 @@ public abstract class StorageControllerGuiBase cachedStacksToDisplay; + private String cachedSearchString; + public StorageControllerGuiBase(T container, Inventory playerInventory, Component name) { super(container, playerInventory, name); this.storageControllerContainer = container; @@ -725,11 +728,18 @@ protected List applySearchToItems() { String searchText = this.searchBar.getValue(); if (!searchText.equals("")) { + if (this.cachedStacksToDisplay != null && this.cachedSearchString != null && this.cachedSearchString.equals(searchText)) + return this.cachedStacksToDisplay; + List stacksToDisplay = new ArrayList<>(); for (ItemStack stack : this.stacks) { if (this.itemMatchesSearch(stack)) stacksToDisplay.add(stack); } + + this.cachedStacksToDisplay = stacksToDisplay; + this.cachedSearchString = searchText; + return stacksToDisplay; } return new ArrayList<>(this.stacks);