Merge pull request #987 from yueh/feature-improve-aeitemstack-compareto

Improved AEItemStack.compareTo performance.
This commit is contained in:
yueh
2015-03-11 16:54:09 +01:00
2 changed files with 16 additions and 8 deletions
@@ -37,7 +37,7 @@ public class AEItemDef
public int def; public int def;
private final int itemID; public final int itemID;
public final Item item; public final Item item;
public int damageValue; public int damageValue;
@@ -62,7 +62,7 @@ public class AEItemDef
public AEItemDef(Item it) { public AEItemDef(Item it) {
this.item = it; this.item = it;
this.itemID = System.identityHashCode( this.item ); this.itemID = Item.getIdFromItem( it );
} }
public AEItemDef copy() public AEItemDef copy()
@@ -261,11 +261,19 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
@Override @Override
public int compareTo(AEItemStack b) public int compareTo(AEItemStack b)
{ {
int id = this.compare( this.def.item.hashCode(), b.def.item.hashCode() ); int id = this.def.itemID - b.def.itemID;
int damageValue = this.compare( this.def.damageValue, b.def.damageValue ); if (id != 0)
int displayDamage = this.compare( this.def.displayDamage, b.def.displayDamage ); return id;
// AELog.info( "NBT: " + nbt );
return id == 0 ? (damageValue == 0 ? (displayDamage == 0 ? this.compareNBT( b.def ) : displayDamage) : damageValue) : 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) private int compareNBT(AEItemDef b)
@@ -276,7 +284,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return nbt; return nbt;
} }
private int compare(int l, long m) private int compare(int l, int m)
{ {
return l < m ? -1 : (l > m ? 1 : 0); return l < m ? -1 : (l > m ? 1 : 0);
} }