From dd5091874dfece083093092af4cbda9ba622537c Mon Sep 17 00:00:00 2001 From: Alfie Cleveland 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 725087de59..5e6cb5d7de 100644 --- a/src/main/java/net/minecraft/server/BlockStateEnum.java +++ b/src/main/java/net/minecraft/server/BlockStateEnum.java @@ -17,6 +17,11 @@ public class BlockStateEnum & INamable> extends BlockState private final ImmutableSet a; private final Map 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 oclass, Collection collection) { super(s, oclass); this.a = ImmutableSet.copyOf(collection); @@ -30,9 +35,10 @@ public class BlockStateEnum & INamable> extends BlockState throw new IllegalArgumentException("Multiple values have the same name \'" + s1 + "\'"); } - this.b.put(s1, oenum); + this.b.put(s1, (T) oenum); // Paper - decompile fix } + this.hashCode = hashId++; // Paper } public Collection d() { @@ -47,24 +53,14 @@ public class BlockStateEnum & INamable> extends BlockState 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 & INamable> BlockStateEnum of(String s, Class oclass) { -- 2.18.0