2020-04-21 22:06:30 +00:00
From bef6f5e0736412aec113d29e4fc408e0596960b8 Mon Sep 17 00:00:00 2001
2019-02-28 06:35:06 +00: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/BlockState.java b/src/main/java/net/minecraft/server/BlockState.java
2020-04-21 22:06:30 +00:00
index 0ce77d92..00e67b56 100644
2019-02-28 06:35:06 +00:00
--- a/src/main/java/net/minecraft/server/BlockState.java
+++ b/src/main/java/net/minecraft/server/BlockState.java
2019-04-27 06:26:04 +00:00
@@ -28,23 +28,13 @@ public abstract class BlockState<T extends Comparable<T>> implements IBlockState
2019-02-28 06:35:06 +00:00
}
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
}
2019-04-27 06:26:04 +00:00
+ private static final java.util.concurrent.atomic.AtomicInteger hashId = new java.util.concurrent.atomic.AtomicInteger(1); // Paper - only one instance per configuration
2019-02-28 06:35:06 +00:00
+ 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;
2019-04-27 06:26:04 +00:00
+ return this.hashCode; // Paper - only one instance per configuration
2019-02-28 06:35:06 +00:00
}
public int c() {
diff --git a/src/main/java/net/minecraft/server/BlockStateBoolean.java b/src/main/java/net/minecraft/server/BlockStateBoolean.java
2020-04-21 22:06:30 +00:00
index d8738447..7ca302b5 100644
2019-02-28 06:35:06 +00:00
--- a/src/main/java/net/minecraft/server/BlockStateBoolean.java
+++ b/src/main/java/net/minecraft/server/BlockStateBoolean.java
2019-04-27 06:26:04 +00:00
@@ -30,8 +30,7 @@ public class BlockStateBoolean extends BlockState<Boolean> {
2019-02-28 06:35:06 +00:00
return obool.toString();
}
2019-04-27 06:26:04 +00:00
- @Override
2019-02-28 06:35:06 +00: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-04-21 22:06:30 +00:00
index 1486d460..7cdadc6b 100644
2019-02-28 06:35:06 +00:00
--- a/src/main/java/net/minecraft/server/BlockStateEnum.java
+++ b/src/main/java/net/minecraft/server/BlockStateEnum.java
2019-04-27 06:26:04 +00:00
@@ -49,8 +49,7 @@ public class BlockStateEnum<T extends Enum<T> & INamable> extends BlockState<T>
2019-02-28 06:35:06 +00:00
return ((INamable) t0).getName();
}
2019-04-27 06:26:04 +00:00
- @Override
2019-02-28 06:35:06 +00: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-04-21 22:06:30 +00:00
index 6f35c365..0499a717 100644
2019-02-28 06:35:06 +00:00
--- a/src/main/java/net/minecraft/server/BlockStateInteger.java
+++ b/src/main/java/net/minecraft/server/BlockStateInteger.java
2019-04-27 06:26:04 +00:00
@@ -38,8 +38,7 @@ public class BlockStateInteger extends BlockState<Integer> {
2019-02-28 06:35:06 +00:00
return this.a;
}
2019-04-27 06:26:04 +00:00
- @Override
2019-02-28 06:35:06 +00: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-04-21 22:06:30 +00:00
2.25.1.windows.1
2019-02-28 06:35:06 +00:00