Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/Spigot-Server-Patches/0151-Optimise-BlockStateEnum-hashCode-and-equals.patch

71 Zeilen
2.5 KiB
Diff

From a447b4a83b584f8af1b4b6d5fb660a9db06d2179 Mon Sep 17 00:00:00 2001
2016-08-19 02:53:36 +02:00
From: Alfie Cleveland <alfeh@me.com>
Date: Fri, 19 Aug 2016 01:52:56 +0100
2016-09-01 00:18:54 +02:00
Subject: [PATCH] Optimise BlockStateEnum hashCode and equals
2016-08-19 02:53:36 +02:00
diff --git a/src/main/java/net/minecraft/server/BlockStateEnum.java b/src/main/java/net/minecraft/server/BlockStateEnum.java
index 21ac1e066..a241d7d8c 100644
2016-08-19 02:53:36 +02:00
--- a/src/main/java/net/minecraft/server/BlockStateEnum.java
+++ b/src/main/java/net/minecraft/server/BlockStateEnum.java
@@ -16,6 +16,11 @@ public class BlockStateEnum<T extends Enum<T> & INamable> extends BlockState<T>
private final ImmutableSet<T> a;
private final Map<String, T> b = Maps.newHashMap();
+ // Paper start - BlockStateEnum is a singleton, so we can use our own hashCode
+ private static int hashId = 0;
+ private int hashCode;
+ // Paper end
+
protected BlockStateEnum(String s, Class<T> oclass, Collection<T> collection) {
super(s, oclass);
this.a = ImmutableSet.copyOf(collection);
@@ -32,6 +37,7 @@ public class BlockStateEnum<T extends Enum<T> & INamable> extends BlockState<T>
this.b.put(s1, (T) oenum);
}
+ this.hashCode = hashId++; // Paper
}
public Collection<T> c() {
2018-01-11 06:31:19 +01:00
@@ -46,32 +52,15 @@ public class BlockStateEnum<T extends Enum<T> & INamable> extends BlockState<T>
2016-08-19 02:53:36 +02:00
return ((INamable) t0).getName();
}
+ @Override // Paper - override equals as BlockStateEnum is a singleton
public boolean equals(Object object) {
- if (this == object) {
- return true;
- } else if (object instanceof BlockStateEnum && super.equals(object)) {
- BlockStateEnum blockstateenum = (BlockStateEnum) object;
-
- return this.a.equals(blockstateenum.a) && this.b.equals(blockstateenum.b);
- } else {
- return false;
- }
+ return this == object;
}
2018-01-11 06:31:19 +01:00
- // Spigot start
- private int hashCode;
+ @Override // Paper - override equals as BlockStateEnum is a singleton
2016-08-19 02:53:36 +02:00
public int hashCode() {
2018-01-11 06:31:19 +01:00
- int hash = hashCode;
- if (hash == 0) {
- int i = super.hashCode();
2016-08-19 02:53:36 +02:00
-
2018-01-11 06:31:19 +01:00
- i = 31 * i + this.a.hashCode();
- i = 31 * i + this.b.hashCode();
- hashCode = hash = i;
- }
- return hash;
2016-08-19 02:53:36 +02:00
+ return hashCode;
}
2018-01-11 06:31:19 +01:00
- // Spigot end
2016-08-19 02:53:36 +02:00
public static <T extends Enum<T> & INamable> BlockStateEnum<T> of(String s, Class<T> oclass) {
2018-01-11 06:31:19 +01:00
return a(s, oclass, Predicates.alwaysTrue());
2016-08-19 02:53:36 +02:00
--
2.18.0
2016-08-19 02:53:36 +02:00