Paper/Spigot-Server-Patches/0184-Optimize-ItemStack.isEmpty.patch
Shane Freeder ffb572ce9a
Remove Ignore invalid Marker Icon ID's in maps
Spigot has patched this issue inside MapIcon, meaning that we no longer need to maintain this patch; Spigots patch also fixes #668 in that it will verify the length of the array, as well as protect against a negative type value being fetched from the array. Only real change is that Spigots patch returns a MapIcon.Type.PLAYER, instead of the RED_MARKER as originally PR'd by Aikar.
2017-04-22 15:52:56 +01:00

32 lines
1.3 KiB
Diff

From 2f31a8392b51b3118e251416709c02fd8251bc05 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 21 Dec 2016 03:48:29 -0500
Subject: [PATCH] Optimize ItemStack.isEmpty()
Remove hashMap lookup every check, simplify code to remove ternary
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
index 911bd879..45ebd3f6 100644
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
@@ -120,9 +120,15 @@ public final class ItemStack {
this.F();
}
+ // Paper start - optimize isEmpty
+ private static Item airItem;
public boolean isEmpty() {
- return this == ItemStack.a ? true : (this.item != null && this.item != Item.getItemOf(Blocks.AIR) ? (this.count <= 0 ? true : this.damage < -32768 || this.damage > '\uffff') : true);
+ if (airItem == null) {
+ airItem = Item.REGISTRY.get(new MinecraftKey("air"));
+ }
+ return this == ItemStack.a || this.item == null || this.item == airItem || (this.count <= 0 || (this.damage < -32768 || this.damage > '\uffff'));
}
+ // Paper end
public static void a(DataConverterManager dataconvertermanager) {
dataconvertermanager.a(DataConverterTypes.ITEM_INSTANCE, (DataInspector) (new DataInspectorBlockEntity()));
--
2.12.2