2018-08-18 06:01:37 +08:00
|
|
|
From 4c81bab2e17f5e9c8afb165cab5b58681596325c Mon Sep 17 00:00:00 2001
|
2018-07-24 00:58:01 +08:00
|
|
|
From: Andrew Steinborn <git@steinborn.me>
|
2018-07-24 01:10:06 +08:00
|
|
|
Date: Mon, 23 Jul 2018 13:08:19 -0400
|
2018-07-24 00:58:01 +08:00
|
|
|
Subject: [PATCH] Optimize RegistryID.c()
|
|
|
|
|
|
|
|
This is a frequent hotspot for world loading/saving.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/RegistryID.java b/src/main/java/net/minecraft/server/RegistryID.java
|
2018-08-18 06:01:37 +08:00
|
|
|
index bde5714dd..a01cda9d8 100644
|
2018-07-24 00:58:01 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/RegistryID.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/RegistryID.java
|
2018-07-24 01:10:06 +08:00
|
|
|
@@ -14,12 +14,14 @@ public class RegistryID<K> implements Registry { // Paper - decompile fix
|
2018-07-24 00:58:01 +08:00
|
|
|
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);
|
2018-07-24 01:10:06 +08:00
|
|
|
this.b = (K[]) (new Object[i]); // Paper - decompile fix
|
2018-07-24 00:58:01 +08:00
|
|
|
this.c = new int[i];
|
2018-07-24 01:10:06 +08:00
|
|
|
this.d = (K[]) (new Object[i]); // Paper - decompile fix
|
2018-07-24 00:58:01 +08:00
|
|
|
+ this.usedIds = new java.util.BitSet(); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getId(@Nullable K k0) {
|
2018-07-24 01:10:06 +08:00
|
|
|
@@ -43,9 +45,14 @@ public class RegistryID<K> implements Registry { // Paper - decompile fix
|
2018-07-24 00:58:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2018-07-24 01:10:06 +08:00
|
|
|
@@ -59,6 +66,7 @@ public class RegistryID<K> implements Registry { // Paper - decompile fix
|
|
|
|
this.d = (K[]) (new Object[i]); // Paper - decompile fix
|
2018-07-24 00:58:01 +08:00
|
|
|
this.e = 0;
|
|
|
|
this.f = 0;
|
|
|
|
+ this.usedIds.clear(); // Paper
|
|
|
|
|
|
|
|
for (int j = 0; j < aobject.length; ++j) {
|
|
|
|
if (aobject[j] != null) {
|
2018-07-24 01:10:06 +08:00
|
|
|
@@ -84,6 +92,7 @@ public class RegistryID<K> implements Registry { // Paper - decompile fix
|
2018-07-24 00:58:01 +08:00
|
|
|
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;
|
2018-07-24 01:10:06 +08:00
|
|
|
@@ -148,6 +157,7 @@ public class RegistryID<K> implements Registry { // Paper - decompile fix
|
2018-07-24 00:58:01 +08:00
|
|
|
Arrays.fill(this.d, (Object) null);
|
|
|
|
this.e = 0;
|
|
|
|
this.f = 0;
|
|
|
|
+ this.usedIds.clear(); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public int b() {
|
|
|
|
--
|
2018-07-25 13:11:08 +08:00
|
|
|
2.18.0
|
2018-07-24 00:58:01 +08:00
|
|
|
|