Fixes #4256: Cache AESharedItemStack#hashCode() (#4257)

This commit is contained in:
yueh
2020-01-16 13:22:42 +01:00
committed by GitHub
parent 1f85d0f607
commit d5fc7a5b21
@@ -38,12 +38,14 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
private final ItemStack itemStack;
private final int itemId;
private final int itemDamage;
private final int hashCode;
public AESharedItemStack( final ItemStack itemStack )
{
this.itemStack = itemStack;
this.itemId = Item.getIdFromItem( itemStack.getItem() );
this.itemDamage = itemStack.getItemDamage();
this.hashCode = this.makeHashCode();
}
Bounds getBounds( final FuzzyMode fuzzy, final boolean ignoreMeta )
@@ -69,7 +71,7 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
@Override
public int hashCode()
{
return Objects.hash( this.itemId, this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
return this.hashCode;
}
@Override
@@ -144,6 +146,11 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
return System.identityHashCode( this.itemStack.getTagCompound() ) - System.identityHashCode( b.getTagCompound() );
}
private int makeHashCode()
{
return Objects.hash( this.itemId, this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
}
/**
* Creates the lower and upper bounds for a specific shared itemstack.
*/