From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Sun, 25 Dec 2022 20:51:32 +0100 Subject: [PATCH] Optimize identical item checks License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html) Gale - https://galemc.org diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java index 2255eaf65338443f0ec99227df0a1e64608ea525..f8963e239354020c8e08460058541ddbaa07798c 100644 --- a/src/main/java/net/minecraft/world/item/ItemStack.java +++ b/src/main/java/net/minecraft/world/item/ItemStack.java @@ -706,14 +706,29 @@ public final class ItemStack { } public static boolean tagMatches(ItemStack left, ItemStack right) { + // Gale start - optimize identical item checks + if (left == right) { + return true; + } + // Gale end - optimize identical item checks return left.isEmpty() && right.isEmpty() ? true : (!left.isEmpty() && !right.isEmpty() ? (left.tag == null && right.tag != null ? false : left.tag == null || left.tag.equals(right.tag)) : false); } public static boolean matches(ItemStack left, ItemStack right) { + // Gale start - optimize identical item checks + if (left == right) { + return true; + } + // Gale end - optimize identical item checks return left.isEmpty() && right.isEmpty() ? true : (!left.isEmpty() && !right.isEmpty() ? left.matches(right) : false); } private boolean matches(ItemStack stack) { + // Gale start - optimize identical item checks + if (this == stack) { + return true; + } + // Gale end - optimize identical item checks return this.count != stack.count ? false : (!this.is(stack.getItem()) ? false : (this.tag == null && stack.tag != null ? false : this.tag == null || this.tag.equals(stack.tag))); }