63 lines
2.3 KiB
Diff
63 lines
2.3 KiB
Diff
From 7064b8b9f50b18bbd81ed129577c4944104ad7d9 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 BlockStateEnum hashCode and equals
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/BlockStateEnum.java b/src/main/java/net/minecraft/server/BlockStateEnum.java
|
|
index 986b9ccea..259da0aa0 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockStateEnum.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockStateEnum.java
|
|
@@ -9,6 +9,7 @@ import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.function.Predicate;
|
|
import java.util.stream.Collectors;
|
|
|
|
@@ -17,6 +18,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 AtomicInteger hashId = new AtomicInteger(1);
|
|
+ private int hashCode;
|
|
+ // Paper end
|
|
+
|
|
protected BlockStateEnum(String s, Class<T> oclass, Collection<T> collection) {
|
|
super(s, oclass);
|
|
this.a = ImmutableSet.copyOf(collection);
|
|
@@ -47,24 +53,14 @@ public class BlockStateEnum<T extends Enum<T> & INamable> extends BlockState<T>
|
|
return ((INamable) t0).getName();
|
|
}
|
|
|
|
+ @Override // Paper start - 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;
|
|
+ // Paper end - override equals as BlockStateEnum is a singleton
|
|
}
|
|
|
|
public int c() {
|
|
- int i = super.c();
|
|
-
|
|
- i = 31 * i + this.a.hashCode();
|
|
- i = 31 * i + this.b.hashCode();
|
|
- return i;
|
|
+ return hashCode; // Paper - hashCode method is final, but we can do this here
|
|
}
|
|
|
|
public static <T extends Enum<T> & INamable> BlockStateEnum<T> of(String s, Class<T> oclass) {
|
|
--
|
|
2.20.1
|
|
|