From d08fdb5182eb3e58369683c117161f5f5099d27c Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Sun, 26 Nov 2023 20:15:18 -0300 Subject: [PATCH 1/2] Optimize "ItemStack#isSimilar(...)" by removing the unnecessary durability check --- ...ck-isSimilar-.-by-removing-the-unnec.patch | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 patches/api/0449-Optimize-ItemStack-isSimilar-.-by-removing-the-unnec.patch diff --git a/patches/api/0449-Optimize-ItemStack-isSimilar-.-by-removing-the-unnec.patch b/patches/api/0449-Optimize-ItemStack-isSimilar-.-by-removing-the-unnec.patch new file mode 100644 index 000000000000..a9594f943bb2 --- /dev/null +++ b/patches/api/0449-Optimize-ItemStack-isSimilar-.-by-removing-the-unnec.patch @@ -0,0 +1,20 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MrPowerGamerBR +Date: Sun, 26 Nov 2023 20:00:50 -0300 +Subject: [PATCH] Optimize "ItemStack#isSimilar(...)" by removing the + unnecessary durability check + + +diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java +index 0af73cc04edb93b9772136d4d808f657ea40e733..36e3fbc727cd748aa138f52976154ba32954cd87 100644 +--- a/src/main/java/org/bukkit/inventory/ItemStack.java ++++ b/src/main/java/org/bukkit/inventory/ItemStack.java +@@ -295,7 +295,7 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat + return true; + } + Material comparisonType = (this.type.isLegacy()) ? Bukkit.getUnsafe().fromLegacy(this.getData(), true) : this.type; // This may be called from legacy item stacks, try to get the right material +- return comparisonType == stack.getType() && getDurability() == stack.getDurability() && hasItemMeta() == stack.hasItemMeta() && (hasItemMeta() ? Bukkit.getItemFactory().equals(getItemMeta(), stack.getItemMeta()) : true); ++ return comparisonType == stack.getType() && /* getDurability() == stack.getDurability() && */hasItemMeta() == stack.hasItemMeta() && (hasItemMeta() ? Bukkit.getItemFactory().equals(getItemMeta(), stack.getItemMeta()) : true); // Paper - remove redundant item durability check + } + + @NotNull From b4e8f0f6160a56518ba903bda94934992c545563 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Sun, 26 Nov 2023 20:32:34 -0300 Subject: [PATCH 2/2] Change patch name and add a better commit message --- ...ve-unnecessary-durability-check-in-ItemStack-isS.patch} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename patches/api/{0449-Optimize-ItemStack-isSimilar-.-by-removing-the-unnec.patch => 0449-Remove-unnecessary-durability-check-in-ItemStack-isS.patch} (66%) diff --git a/patches/api/0449-Optimize-ItemStack-isSimilar-.-by-removing-the-unnec.patch b/patches/api/0449-Remove-unnecessary-durability-check-in-ItemStack-isS.patch similarity index 66% rename from patches/api/0449-Optimize-ItemStack-isSimilar-.-by-removing-the-unnec.patch rename to patches/api/0449-Remove-unnecessary-durability-check-in-ItemStack-isS.patch index a9594f943bb2..215fc0e43532 100644 --- a/patches/api/0449-Optimize-ItemStack-isSimilar-.-by-removing-the-unnec.patch +++ b/patches/api/0449-Remove-unnecessary-durability-check-in-ItemStack-isS.patch @@ -1,9 +1,12 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Sun, 26 Nov 2023 20:00:50 -0300 -Subject: [PATCH] Optimize "ItemStack#isSimilar(...)" by removing the - unnecessary durability check +Subject: [PATCH] Remove unnecessary durability check in + "ItemStack#isSimilar(...)" +By removing this check we avoid unnecessarily allocating useless `ItemMeta` objects if we are comparing two items, or one of the two items, that don't have any durability. Don't worry, the durability of the item is checked when it checks if both item metas are equal. + +This is a leftover from when checking for the item's durability was "free" because the durability was stored in the `ItemStack` itself, this [was changed in Minecraft 1.13](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/f8b2086d60942eb2cd7ac25a2a1408cb790c222c#src/main/java/org/bukkit/inventory/ItemStack.java). diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java index 0af73cc04edb93b9772136d4d808f657ea40e733..36e3fbc727cd748aa138f52976154ba32954cd87 100644