From 71971a01ca9ff09d220a49970255069a8efe0046 Mon Sep 17 00:00:00 2001 From: AlexIIL Date: Wed, 25 Dec 2019 13:01:21 +0000 Subject: Optimise EntryRegistryImpl.registerEntries by first checking in a set to see if the given entry already exists before adding it, instead of looping through the whole list to see if any of them match. --- .../java/me/shedaniel/rei/impl/ItemEntryStack.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java') diff --git a/src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java b/src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java index 5aa6d7072..3778cd5f0 100644 --- a/src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java +++ b/src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java @@ -34,6 +34,7 @@ import java.util.Optional; public class ItemEntryStack extends AbstractEntryStack { private ItemStack itemStack; + private int hash = -1; public ItemEntryStack(ItemStack itemStack) { this.itemStack = itemStack; @@ -57,6 +58,7 @@ public class ItemEntryStack extends AbstractEntryStack { @Override public void setAmount(int amount) { itemStack.setCount(amount); + hash = -1; } @Override @@ -114,12 +116,18 @@ public class ItemEntryStack extends AbstractEntryStack { @Override public int hashCode() { - int result = 1; - result = 31 * result + getType().ordinal(); - result = 31 * result + itemStack.getItem().hashCode(); - result = 31 * result + itemStack.getCount(); - result = 31 * result + (itemStack.hasTag() ? itemStack.getTag().hashCode() : 0); - return result; + if (hash == -1) { + int result = 1; + result = 31 * result + getType().ordinal(); + result = 31 * result + itemStack.getItem().hashCode(); + result = 31 * result + itemStack.getCount(); + result = 31 * result + (itemStack.hasTag() ? itemStack.getTag().hashCode() : 0); + hash = result; + if (hash == -1) { + hash = -2; + } + } + return hash; } @Nullable -- cgit