Fixes slow oredict comparison, fixes #1044
This commit is contained in:
@@ -118,9 +118,19 @@ public interface IRSAPI {
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -186,8 +186,8 @@ public class API implements IRSAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemStackHashCode(ItemStack stack) {
|
||||
return stack.getItem().hashCode() * (stack.getItemDamage() + 1) * (stack.hasTagCompound() ? stack.getTagCompound().hashCode() : 1);
|
||||
public int getItemStackHashCode(ItemStack stack, boolean tag) {
|
||||
return stack.getItem().hashCode() * (stack.getItemDamage() + 1) * ((tag && stack.hasTagCompound()) ? stack.getTagCompound().hashCode() : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -117,8 +117,9 @@ public class Comparer implements IComparer {
|
||||
return validity == EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
int code = API.instance().getItemStackHashCode(left);
|
||||
code = 31 * code + API.instance().getItemStackHashCode(right);
|
||||
// We do not care about the NBT tag since the oredict doesn't care either, and generating a NBT hashcode is slow.
|
||||
int code = API.instance().getItemStackHashCode(left, false);
|
||||
code = 31 * code + API.instance().getItemStackHashCode(right, false);
|
||||
|
||||
if (oredictCache.containsKey(code)) {
|
||||
return oredictCache.get(code);
|
||||
|
||||
Reference in New Issue
Block a user