From a433532fe8ca7dd2228d7bc2564aa4c5b829ec7d Mon Sep 17 00:00:00 2001 From: Raoul Van den Berge Date: Tue, 24 May 2016 23:33:45 +0200 Subject: [PATCH] Performance improvements to grids --- CHANGELOG.md | 1 + src/main/java/refinedstorage/gui/GuiGrid.java | 10 +++++----- src/main/java/refinedstorage/storage/ItemGroup.java | 9 +++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cd71f406..afb785dd6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fixed going out of crafting GUI not restoring state (scrollbar and search term) - Fixed not being able to create a pattern in disconnected Pattern Grid - Fixed not being able to place cake or string +- Performance improvements to Grids ### 0.7 **Bugfixes** diff --git a/src/main/java/refinedstorage/gui/GuiGrid.java b/src/main/java/refinedstorage/gui/GuiGrid.java index c376eb473..58ef3d817 100755 --- a/src/main/java/refinedstorage/gui/GuiGrid.java +++ b/src/main/java/refinedstorage/gui/GuiGrid.java @@ -100,7 +100,7 @@ public class GuiGrid extends GuiBase { while (t.hasNext()) { ItemGroup group = t.next(); - if (!group.toStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase())) { + if (!group.toCachedStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase())) { t.remove(); } } @@ -110,9 +110,9 @@ public class GuiGrid extends GuiBase { @Override public int compare(ItemGroup left, ItemGroup right) { if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_ASCENDING) { - return right.toStack().getDisplayName().compareTo(left.toStack().getDisplayName()); + return right.toCachedStack().getDisplayName().compareTo(left.toCachedStack().getDisplayName()); } else if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_DESCENDING) { - return left.toStack().getDisplayName().compareTo(right.toStack().getDisplayName()); + return left.toCachedStack().getDisplayName().compareTo(right.toCachedStack().getDisplayName()); } return 0; @@ -259,7 +259,7 @@ public class GuiGrid extends GuiBase { text = String.valueOf(qty); } - drawItem(x, y, items.get(slot).toStack(), true, text); + drawItem(x, y, items.get(slot).toCachedStack(), true, text); } if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) { @@ -287,7 +287,7 @@ public class GuiGrid extends GuiBase { } if (isHoveringOverItemInSlot()) { - drawTooltip(mouseX, mouseY, items.get(hoveringSlot).toStack()); + drawTooltip(mouseX, mouseY, items.get(hoveringSlot).toCachedStack()); } if (isHoveringOverClear(mouseX, mouseY)) { diff --git a/src/main/java/refinedstorage/storage/ItemGroup.java b/src/main/java/refinedstorage/storage/ItemGroup.java index 252b16075..79f577e35 100755 --- a/src/main/java/refinedstorage/storage/ItemGroup.java +++ b/src/main/java/refinedstorage/storage/ItemGroup.java @@ -14,6 +14,7 @@ public class ItemGroup { private NBTTagCompound tag; // Used clientside private int id; + private ItemStack cachedStack; public ItemGroup(ByteBuf buf) { this.id = buf.readInt(); @@ -165,4 +166,12 @@ public class ItemGroup { return stack; } + + public ItemStack toCachedStack() { + if (cachedStack == null) { + cachedStack = toStack(); + } + + return cachedStack; + } }