2016-08-31 22:18:54 +00:00
|
|
|
From 64360e184599c895a9c26a46cf1e7e2f91e80b92 Mon Sep 17 00:00:00 2001
|
2016-08-19 00:53:36 +00:00
|
|
|
From: Alfie Cleveland <alfeh@me.com>
|
|
|
|
Date: Fri, 19 Aug 2016 01:52:56 +0100
|
2016-08-31 22:18:54 +00:00
|
|
|
Subject: [PATCH] Optimise BlockStateEnum hashCode and equals
|
2016-08-19 00:53:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/BlockStateEnum.java b/src/main/java/net/minecraft/server/BlockStateEnum.java
|
|
|
|
index 288c52c..66c459d 100644
|
|
|
|
--- 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() {
|
|
|
|
@@ -46,24 +52,14 @@ public class BlockStateEnum<T extends Enum<T> & INamable> extends BlockState<T>
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ @Override // Paper - override hashCode as BlockStateEnum is a singleton
|
|
|
|
public int hashCode() {
|
|
|
|
- int i = super.hashCode();
|
|
|
|
-
|
|
|
|
- i = 31 * i + this.a.hashCode();
|
|
|
|
- i = 31 * i + this.b.hashCode();
|
|
|
|
- return i;
|
|
|
|
+ return hashCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T extends Enum<T> & INamable> BlockStateEnum<T> of(String s, Class<T> oclass) {
|
|
|
|
--
|
2016-08-31 22:18:54 +00:00
|
|
|
2.9.3
|
2016-08-19 00:53:36 +00:00
|
|
|
|