3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/Spigot-Server-Patches/0111-Optimise-BlockState-s-hashCode-equals.patch
Aikar 36f34f01c0
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
da9ef3c5 #496: Add methods to get/set ItemStacks in EquipmentSlots
3abebc9f #492: Let Tameable extend Animals rather than Entity
941111a0 #495: Expose ItemStack and hand used in PlayerShearEntityEvent
4fe19cae #494: InventoryView - Add missing Brewing FUEL_TIME

CraftBukkit Changes:
933e9094 #664: Add methods to get/set ItemStacks in EquipmentSlots
18722312 #662: Expose ItemStack and hand used in PlayerShearEntityEvent
2020-05-06 06:05:22 -04:00

85 Zeilen
3.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alfie Cleveland <alfeh@me.com>
Date: Fri, 19 Aug 2016 01:52:56 +0100
Subject: [PATCH] Optimise BlockState's hashCode/equals
These are singleton "single instance" objects. We can rely on
object identity checks safely.
Use a simpler optimized hashcode
diff --git a/src/main/java/net/minecraft/server/BlockState.java b/src/main/java/net/minecraft/server/BlockState.java
index 0ce77d9230f3d1c53df7c5b72a380a2fa0c6d882..00e67b567f00824b25b45e5ff5ecd62c87ea0309 100644
--- a/src/main/java/net/minecraft/server/BlockState.java
+++ b/src/main/java/net/minecraft/server/BlockState.java
@@ -28,23 +28,13 @@ public abstract class BlockState<T extends Comparable<T>> implements IBlockState
}
public boolean equals(Object object) {
- if (this == object) {
- return true;
- } else if (!(object instanceof BlockState)) {
- return false;
- } else {
- BlockState<?> blockstate = (BlockState) object;
-
- return this.a.equals(blockstate.a) && this.b.equals(blockstate.b);
- }
+ return this == object; // Paper - only one instance per configuration
}
+ private static final java.util.concurrent.atomic.AtomicInteger hashId = new java.util.concurrent.atomic.AtomicInteger(1); // Paper - only one instance per configuration
+ private final int hashCode = 92821 * hashId.getAndIncrement(); // Paper - only one instance per configuration
public final int hashCode() {
- if (this.c == null) {
- this.c = this.c();
- }
-
- return this.c;
+ return this.hashCode; // Paper - only one instance per configuration
}
public int c() {
diff --git a/src/main/java/net/minecraft/server/BlockStateBoolean.java b/src/main/java/net/minecraft/server/BlockStateBoolean.java
index d8738447d794f6967307daa1271473903b76a632..7ca302b522df081755120c597a08d589193c57a6 100644
--- a/src/main/java/net/minecraft/server/BlockStateBoolean.java
+++ b/src/main/java/net/minecraft/server/BlockStateBoolean.java
@@ -30,8 +30,7 @@ public class BlockStateBoolean extends BlockState<Boolean> {
return obool.toString();
}
- @Override
- public boolean equals(Object object) {
+ public boolean equals_unused(Object object) { // Paper
if (this == object) {
return true;
} else if (object instanceof BlockStateBoolean && super.equals(object)) {
diff --git a/src/main/java/net/minecraft/server/BlockStateEnum.java b/src/main/java/net/minecraft/server/BlockStateEnum.java
index 1486d460c8ec3d117b4dc3d28b2c3f1b632e187b..7cdadc6b6abd069f9a1bc000a8f116f73b90e029 100644
--- a/src/main/java/net/minecraft/server/BlockStateEnum.java
+++ b/src/main/java/net/minecraft/server/BlockStateEnum.java
@@ -49,8 +49,7 @@ public class BlockStateEnum<T extends Enum<T> & INamable> extends BlockState<T>
return ((INamable) t0).getName();
}
- @Override
- public boolean equals(Object object) {
+ public boolean equals_unused(Object object) { // Paper
if (this == object) {
return true;
} else if (object instanceof BlockStateEnum && super.equals(object)) {
diff --git a/src/main/java/net/minecraft/server/BlockStateInteger.java b/src/main/java/net/minecraft/server/BlockStateInteger.java
index 6f35c365f9086a2289e17b4d8e73757ad2c7f87b..0499a71705f3bdac6c94a8dc340cc15e96d9586e 100644
--- a/src/main/java/net/minecraft/server/BlockStateInteger.java
+++ b/src/main/java/net/minecraft/server/BlockStateInteger.java
@@ -38,8 +38,7 @@ public class BlockStateInteger extends BlockState<Integer> {
return this.a;
}
- @Override
- public boolean equals(Object object) {
+ public boolean equals_unused(Object object) { // Paper
if (this == object) {
return true;
} else if (object instanceof BlockStateInteger && super.equals(object)) {