mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 03:32:46 +01:00
Optimize ItemStack.isEmpty()
Remove hashMap lookup every check, simplify code to remove ternary
This commit is contained in:
parent
417b1e2e02
commit
257c591391
1 changed files with 31 additions and 0 deletions
31
Spigot-Server-Patches/0188-Optimize-ItemStack.isEmpty.patch
Normal file
31
Spigot-Server-Patches/0188-Optimize-ItemStack.isEmpty.patch
Normal file
|
@ -0,0 +1,31 @@
|
|||
From 3ec4007a5c8e90d22c60d308a21d858e0cfcccc8 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 c8694e8b9..23c975891 100644
|
||||
--- a/src/main/java/net/minecraft/server/ItemStack.java
|
||||
+++ b/src/main/java/net/minecraft/server/ItemStack.java
|
||||
@@ -112,9 +112,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.getItemOf(Blocks.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.11.0
|
||||
|
Loading…
Reference in a new issue