PaperMC/Spigot-Server-Patches/Optimise-BlockState-s-hashCode-equals.patch

85 lines
3.8 KiB
Diff
Raw Normal View History

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
2020-06-25 03:10:30 +02:00
diff --git a/src/main/java/net/minecraft/server/IBlockState.java b/src/main/java/net/minecraft/server/IBlockState.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
2020-06-25 03:10:30 +02:00
--- a/src/main/java/net/minecraft/server/IBlockState.java
+++ b/src/main/java/net/minecraft/server/IBlockState.java
@@ -0,0 +0,0 @@ public abstract class IBlockState<T extends Comparable<T>>
}
public boolean equals(Object object) {
- if (this == object) {
- return true;
2020-06-25 03:10:30 +02:00
- } else if (!(object instanceof IBlockState)) {
- return false;
- } else {
2020-06-25 03:10:30 +02:00
- IBlockState<?> blockstate = (IBlockState) object;
-
- return this.a.equals(blockstate.a) && this.b.equals(blockstate.b);
- }
+ return this == object; // Paper - only one instance per configuration
}
2019-04-27 08:26:04 +02:00
+ 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;
2019-04-27 08:26:04 +02:00
+ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- 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
@@ -0,0 +0,0 @@ public class BlockStateBoolean extends IBlockState<Boolean> {
return obool.toString();
}
2019-04-27 08:26:04 +02:00
- @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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- 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
@@ -0,0 +0,0 @@ public class BlockStateEnum<T extends Enum<T> & INamable> extends IBlockState<T>
return ((INamable) t0).getName();
}
2019-04-27 08:26:04 +02:00
- @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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- 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
@@ -0,0 +0,0 @@ public class BlockStateInteger extends IBlockState<Integer> {
return this.a;
}
2019-04-27 08:26:04 +02:00
- @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)) {