Fixes slow oredict comparison, fixes #1044
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user