From 53f448e5789290115d4d1f5bd38ffea57a8ff4ff Mon Sep 17 00:00:00 2001 From: yueh Date: Sun, 8 Mar 2015 15:27:27 +0100 Subject: [PATCH] Improved AEItemStack.compareTo performance. --- src/main/java/appeng/util/item/AEItemDef.java | 4 ++-- .../java/appeng/util/item/AEItemStack.java | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/appeng/util/item/AEItemDef.java b/src/main/java/appeng/util/item/AEItemDef.java index f3573940..bf10167c 100644 --- a/src/main/java/appeng/util/item/AEItemDef.java +++ b/src/main/java/appeng/util/item/AEItemDef.java @@ -37,7 +37,7 @@ public class AEItemDef public int def; - private final int itemID; + public final int itemID; public final Item item; public int damageValue; @@ -62,7 +62,7 @@ public class AEItemDef public AEItemDef(Item it) { this.item = it; - this.itemID = System.identityHashCode( this.item ); + this.itemID = Item.getIdFromItem( it ); } public AEItemDef copy() diff --git a/src/main/java/appeng/util/item/AEItemStack.java b/src/main/java/appeng/util/item/AEItemStack.java index 099899b3..5c35706f 100644 --- a/src/main/java/appeng/util/item/AEItemStack.java +++ b/src/main/java/appeng/util/item/AEItemStack.java @@ -261,11 +261,19 @@ public final class AEItemStack extends AEStack implements IAEItemS @Override public int compareTo(AEItemStack b) { - int id = this.compare( this.def.item.hashCode(), b.def.item.hashCode() ); - int damageValue = this.compare( this.def.damageValue, b.def.damageValue ); - int displayDamage = this.compare( this.def.displayDamage, b.def.displayDamage ); - // AELog.info( "NBT: " + nbt ); - return id == 0 ? (damageValue == 0 ? (displayDamage == 0 ? this.compareNBT( b.def ) : displayDamage) : damageValue) : id; + int id = this.def.itemID - b.def.itemID; + if (id != 0) + return id; + + int damageValue = this.def.damageValue - b.def.damageValue ; + if (damageValue != 0) + return damageValue; + + int displayDamage = this.def.displayDamage - b.def.displayDamage; + if (displayDamage != 0) + return displayDamage; + + return (this.def.tagCompound == b.def.tagCompound) ? 0 : this.compareNBT( b.def ); } private int compareNBT(AEItemDef b) @@ -276,7 +284,7 @@ public final class AEItemStack extends AEStack implements IAEItemS return nbt; } - private int compare(int l, long m) + private int compare(int l, int m) { return l < m ? -1 : (l > m ? 1 : 0); }