From d9afd08ceea0cddec8de06b5048f8b5193a4b5f3 Mon Sep 17 00:00:00 2001 From: Alfie Cleveland Date: Fri, 19 Aug 2016 01:53:36 +0100 Subject: [PATCH] Optimise BlockStateEnum --- Spigot-Server-Patches/0003-MC-Dev-fixes.patch | 17 ++++- .../0169-Optimise-hashCode-and-equals.patch | 62 +++++++++++++++++++ scripts/importmcdev.sh | 1 + 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 Spigot-Server-Patches/0169-Optimise-hashCode-and-equals.patch diff --git a/Spigot-Server-Patches/0003-MC-Dev-fixes.patch b/Spigot-Server-Patches/0003-MC-Dev-fixes.patch index f2860c8b1..9a12c0c81 100644 --- a/Spigot-Server-Patches/0003-MC-Dev-fixes.patch +++ b/Spigot-Server-Patches/0003-MC-Dev-fixes.patch @@ -1,4 +1,4 @@ -From ab811322114f49feeb05a587ce46cc6dc08a21a8 Mon Sep 17 00:00:00 2001 +From bd8f9fe1de9b9e80ac852d851b6f7d58aecfec55 Mon Sep 17 00:00:00 2001 From: Aikar Date: Wed, 30 Mar 2016 19:36:20 -0400 Subject: [PATCH] MC Dev fixes @@ -30,6 +30,19 @@ index 059c96f..ab04f9c 100644 } @Nullable +diff --git a/src/main/java/net/minecraft/server/BlockStateEnum.java b/src/main/java/net/minecraft/server/BlockStateEnum.java +index 71524f2..288c52c 100644 +--- a/src/main/java/net/minecraft/server/BlockStateEnum.java ++++ b/src/main/java/net/minecraft/server/BlockStateEnum.java +@@ -29,7 +29,7 @@ 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); + } + + } diff --git a/src/main/java/net/minecraft/server/CommandAbstract.java b/src/main/java/net/minecraft/server/CommandAbstract.java index 7876457..20572d4 100644 --- a/src/main/java/net/minecraft/server/CommandAbstract.java @@ -66,5 +79,5 @@ index f5bcbdb..3190cad 100644 for (ZipEntry clazzEntry; (clazzEntry = nmsZipStream.getNextEntry()) != null; ) { final String entryName = clazzEntry.getName(); -- -2.8.3 +2.7.4 (Apple Git-66) diff --git a/Spigot-Server-Patches/0169-Optimise-hashCode-and-equals.patch b/Spigot-Server-Patches/0169-Optimise-hashCode-and-equals.patch new file mode 100644 index 000000000..c7ad083f1 --- /dev/null +++ b/Spigot-Server-Patches/0169-Optimise-hashCode-and-equals.patch @@ -0,0 +1,62 @@ +From cf89a908ea5b10f48d8709d72f6c7eaf252a3fd1 Mon Sep 17 00:00:00 2001 +From: Alfie Cleveland +Date: Fri, 19 Aug 2016 01:52:56 +0100 +Subject: [PATCH] Optimise hashCode and equals + + +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 & 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); +@@ -32,6 +37,7 @@ public class BlockStateEnum & INamable> extends BlockState + this.b.put(s1, (T) oenum); + } + ++ this.hashCode = hashId++; // Paper + } + + public Collection c() { +@@ -46,24 +52,14 @@ public class BlockStateEnum & INamable> extends BlockState + 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 & INamable> BlockStateEnum of(String s, Class oclass) { +-- +2.9.2.windows.1 + diff --git a/scripts/importmcdev.sh b/scripts/importmcdev.sh index 9247bc9d9..1f8bf8598 100755 --- a/scripts/importmcdev.sh +++ b/scripts/importmcdev.sh @@ -45,6 +45,7 @@ import BlockFluids import BlockFurnace import BlockIceFrost import BlockPosition +import BlockStateEnum import ChunkCache import ChunkProviderFlat import ChunkProviderGenerate