2019-04-30 01:20:24 +00:00
|
|
|
From 6d8bc880e02369cc0c7c8db23895c3c8c3e1459b Mon Sep 17 00:00:00 2001
|
2018-07-23 16:58:01 +00:00
|
|
|
From: Andrew Steinborn <git@steinborn.me>
|
2018-07-23 17:10:06 +00:00
|
|
|
Date: Mon, 23 Jul 2018 13:08:19 -0400
|
2018-07-23 16:58:01 +00: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
|
2019-04-30 01:20:24 +00:00
|
|
|
index e15d28671..e8a48b9a4 100644
|
2018-07-23 16:58:01 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/RegistryID.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/RegistryID.java
|
2019-01-01 03:15:55 +00:00
|
|
|
@@ -14,12 +14,14 @@ public class RegistryID<K> implements Registry<K> {
|
2018-07-23 16:58:01 +00:00
|
|
|
private K[] d;
|
|
|
|
private int e;
|
|
|
|
private int f;
|
|
|
|
+ private java.util.BitSet usedIds; // Paper
|
|
|
|
|
|
|
|
public RegistryID(int i) {
|
2019-01-01 03:15:55 +00:00
|
|
|
i = (int) ((float) i / 0.8F);
|
|
|
|
this.b = (K[]) (new Object[i]); // Paper - decompile fix
|
2018-07-23 16:58:01 +00:00
|
|
|
this.c = new int[i];
|
2019-01-01 03:15:55 +00:00
|
|
|
this.d = (K[]) (new Object[i]); // Paper - decompile fix
|
2018-07-23 16:58:01 +00:00
|
|
|
+ this.usedIds = new java.util.BitSet(); // Paper
|
|
|
|
}
|
|
|
|
|
2019-01-01 03:15:55 +00:00
|
|
|
public int getId(@Nullable K k0) {
|
2019-04-30 01:20:24 +00:00
|
|
|
@@ -44,9 +46,14 @@ public class RegistryID<K> implements Registry<K> {
|
2018-07-23 16:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private int c() {
|
|
|
|
+ // Paper start
|
|
|
|
+ /*
|
2019-01-01 03:15:55 +00:00
|
|
|
while (this.e < this.d.length && this.d[this.e] != null) {
|
2018-07-23 16:58:01 +00:00
|
|
|
++this.e;
|
|
|
|
}
|
|
|
|
+ */
|
|
|
|
+ this.e = this.usedIds.nextClearBit(0);
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
return this.e;
|
|
|
|
}
|
2019-04-30 01:20:24 +00:00
|
|
|
@@ -60,6 +67,7 @@ public class RegistryID<K> implements Registry<K> {
|
2019-01-01 03:15:55 +00:00
|
|
|
this.d = (K[]) (new Object[i]); // Paper - decompile fix
|
2018-07-23 16:58:01 +00:00
|
|
|
this.e = 0;
|
|
|
|
this.f = 0;
|
|
|
|
+ this.usedIds.clear(); // Paper
|
|
|
|
|
2019-01-01 03:15:55 +00:00
|
|
|
for (int j = 0; j < ak.length; ++j) {
|
|
|
|
if (ak[j] != null) {
|
2019-04-30 01:20:24 +00:00
|
|
|
@@ -85,6 +93,7 @@ public class RegistryID<K> implements Registry<K> {
|
2019-01-01 03:15:55 +00:00
|
|
|
this.b[k] = k0;
|
|
|
|
this.c[k] = i;
|
|
|
|
this.d[i] = k0;
|
2018-07-23 16:58:01 +00:00
|
|
|
+ this.usedIds.set(i); // Paper
|
|
|
|
++this.f;
|
|
|
|
if (i == this.e) {
|
|
|
|
++this.e;
|
2019-04-30 01:20:24 +00:00
|
|
|
@@ -149,6 +158,7 @@ public class RegistryID<K> implements Registry<K> {
|
2019-01-01 03:15:55 +00:00
|
|
|
Arrays.fill(this.d, (Object) null);
|
2018-07-23 16:58:01 +00:00
|
|
|
this.e = 0;
|
|
|
|
this.f = 0;
|
|
|
|
+ this.usedIds.clear(); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public int b() {
|
|
|
|
--
|
2019-03-20 01:46:00 +00:00
|
|
|
2.21.0
|
2018-07-23 16:58:01 +00:00
|
|
|
|