2020-05-06 11:48:49 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2019-02-28 07:35:06 +01:00
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/BlockStateBoolean.java b/src/main/java/net/minecraft/server/BlockStateBoolean.java
2020-06-25 14:04:34 +02:00
index 8df150f4cabb3dd98cb66c9d1af7fae035a6a6fe..4ca8db630434915de4eaeac6c4ecd60714d7f5d9 100644
2019-02-28 07:35:06 +01:00
--- a/src/main/java/net/minecraft/server/BlockStateBoolean.java
+++ b/src/main/java/net/minecraft/server/BlockStateBoolean.java
2020-06-25 03:10:30 +02:00
@@ -30,8 +30,7 @@ public class BlockStateBoolean extends IBlockState<Boolean> {
2019-02-28 07:35:06 +01:00
return obool.toString();
}
2019-04-27 08:26:04 +02:00
- @Override
2019-02-28 07:35:06 +01:00
- 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
2020-06-25 14:04:34 +02:00
index 8162c11d14b8e88c2b572f9ddf6b7a15977047f8..8dc620b22bb904aa6a82e2127aa9da861986525c 100644
2019-02-28 07:35:06 +01:00
--- a/src/main/java/net/minecraft/server/BlockStateEnum.java
+++ b/src/main/java/net/minecraft/server/BlockStateEnum.java
2020-06-25 03:10:30 +02:00
@@ -49,8 +49,7 @@ public class BlockStateEnum<T extends Enum<T> & INamable> extends IBlockState<T>
2019-02-28 07:35:06 +01:00
return ((INamable) t0).getName();
}
2019-04-27 08:26:04 +02:00
- @Override
2019-02-28 07:35:06 +01:00
- 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
2020-06-25 14:04:34 +02:00
index 5bd7a236b948666ca31e53cb3a8aa0dc147e274b..36b84446e96faefad3b783f73df74e0f3bce8255 100644
2019-02-28 07:35:06 +01:00
--- a/src/main/java/net/minecraft/server/BlockStateInteger.java
+++ b/src/main/java/net/minecraft/server/BlockStateInteger.java
2020-06-25 03:10:30 +02:00
@@ -38,8 +38,7 @@ public class BlockStateInteger extends IBlockState<Integer> {
2019-02-28 07:35:06 +01:00
return this.a;
}
2019-04-27 08:26:04 +02:00
- @Override
2019-02-28 07:35:06 +01:00
- 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)) {
2020-06-25 14:04:34 +02:00
diff --git a/src/main/java/net/minecraft/server/IBlockState.java b/src/main/java/net/minecraft/server/IBlockState.java
index 88f1f201240ef0479c4f0f93f4caca454bbe7e9e..4eea3a4fca4cea96109e54473335fd3660e2f6d6 100644
--- a/src/main/java/net/minecraft/server/IBlockState.java
+++ b/src/main/java/net/minecraft/server/IBlockState.java
@@ -21,7 +21,7 @@ public abstract class IBlockState<T extends Comparable<T>> {
return DataResult.error("Unable to read property: " + this + " with value: " + s1);
});
}, this::a);
- this.e = this.d.xmap(this::b, IBlockState.a::b);
+ this.e = this.d.xmap(this::b, (IBlockState.a<T> param) -> { return param.b(); }); // Paper - decompile fix
this.a = oclass;
this.b = s;
}
@@ -61,23 +61,17 @@ public abstract class IBlockState<T extends Comparable<T>> {
}
public boolean equals(Object object) {
- if (this == object) {
- return true;
- } else if (!(object instanceof IBlockState)) {
- return false;
- } else {
- IBlockState<?> iblockstate = (IBlockState) object;
-
- return this.a.equals(iblockstate.a) && this.b.equals(iblockstate.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.b();
}
- return this.c;
+ return this.hashCode; // Paper - only one instance per configuration
}
public int b() {