From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 23 Jul 2018 13:08:19 -0400 Subject: [PATCH] Optimize RegistryID.c() This is a frequent hotspot for world loading/saving. diff --git a/src/main/java/net/minecraft/util/RegistryID.java b/src/main/java/net/minecraft/util/RegistryID.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/util/RegistryID.java +++ b/src/main/java/net/minecraft/util/RegistryID.java @@ -0,0 +0,0 @@ public class RegistryID implements Registry { private K[] d; private int e; private int f; + private java.util.BitSet usedIds; // Paper public RegistryID(int i) { i = (int) ((float) i / 0.8F); this.b = (K[]) (new Object[i]); // Paper - decompile fix this.c = new int[i]; this.d = (K[]) (new Object[i]); // Paper - decompile fix + this.usedIds = new java.util.BitSet(); // Paper } // Paper start - decompile fix @@ -0,0 +0,0 @@ public class RegistryID implements Registry { } private int c() { + // Paper start + /* while (this.e < this.d.length && this.d[this.e] != null) { ++this.e; } + */ + this.e = this.usedIds.nextClearBit(0); + // Paper end return this.e; } @@ -0,0 +0,0 @@ public class RegistryID implements Registry { this.d = (K[]) (new Object[i]); // Paper - decompile fix this.e = 0; this.f = 0; + this.usedIds.clear(); // Paper for (int j = 0; j < ak.length; ++j) { if (ak[j] != null) { @@ -0,0 +0,0 @@ public class RegistryID implements Registry { this.b[k] = k0; this.c[k] = i; this.d[i] = k0; + this.usedIds.set(i); // Paper ++this.f; if (i == this.e) { ++this.e; @@ -0,0 +0,0 @@ public class RegistryID implements Registry { Arrays.fill(this.d, (Object) null); this.e = 0; this.f = 0; + this.usedIds.clear(); // Paper } public int b() {