Fixes slow oredict comparison, fixes #1044

This commit is contained in:
raoulvdberge
2017-03-11 12:23:16 +01:00
parent f5128e1f20
commit 2c80231098
3 changed files with 16 additions and 5 deletions

View File

@@ -118,9 +118,19 @@ public interface IRSAPI {
/** /**
* @param stack the stack * @param stack the stack
* @param tag whether the NBT tag of the stack should be calculated in the hashcode
* @return a hashcode for the given stack * @return a hashcode for the given stack
*/ */
int getItemStackHashCode(ItemStack stack); int getItemStackHashCode(ItemStack stack, boolean tag);
/**
* @param stack the stack
* @return a hashcode for the given stack
*/
default int getItemStackHashCode(ItemStack stack) {
return getItemStackHashCode(stack, true);
}
/** /**
* @param stack the stack * @param stack the stack

View File

@@ -186,8 +186,8 @@ public class API implements IRSAPI {
} }
@Override @Override
public int getItemStackHashCode(ItemStack stack) { public int getItemStackHashCode(ItemStack stack, boolean tag) {
return stack.getItem().hashCode() * (stack.getItemDamage() + 1) * (stack.hasTagCompound() ? stack.getTagCompound().hashCode() : 1); return stack.getItem().hashCode() * (stack.getItemDamage() + 1) * ((tag && stack.hasTagCompound()) ? stack.getTagCompound().hashCode() : 1);
} }
@Override @Override

View File

@@ -117,8 +117,9 @@ public class Comparer implements IComparer {
return validity == EnumActionResult.SUCCESS; return validity == EnumActionResult.SUCCESS;
} }
int code = API.instance().getItemStackHashCode(left); // We do not care about the NBT tag since the oredict doesn't care either, and generating a NBT hashcode is slow.
code = 31 * code + API.instance().getItemStackHashCode(right); int code = API.instance().getItemStackHashCode(left, false);
code = 31 * code + API.instance().getItemStackHashCode(right, false);
if (oredictCache.containsKey(code)) { if (oredictCache.containsKey(code)) {
return oredictCache.get(code); return oredictCache.get(code);