Paper/patches/server/0120-Optimize-ItemStack.isEmpty.patch

21 lines
1000 B
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 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/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 9b358c8e464c67c4953749cda6d2983db98e0c5f..a598b6522ce4d41575f04425d189319fa12a7b70 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -252,7 +252,7 @@ public final class ItemStack {
2021-06-11 14:02:28 +02:00
}
public boolean isEmpty() {
- return this == ItemStack.EMPTY ? true : (this.getItem() != null && !this.is(Items.AIR) ? this.count <= 0 : true);
+ return this == ItemStack.EMPTY || this.item == null || this.item == Items.AIR || this.count <= 0; // Paper
2021-06-11 14:02:28 +02:00
}
2022-12-07 19:52:24 +01:00
public boolean isItemEnabled(FeatureFlagSet enabledFeatures) {