2018-09-01 06:56:57 +08:00
|
|
|
From b30fb91663c75adb7a5138e6f03a70c63d93c0f6 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-09-01 06:56:57 +08:00
|
|
|
index d03ac0e70c..9242999f70 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-09-01 06:56:57 +08:00
|
|
|
@@ -13,12 +13,14 @@ public class RegistryID<K> implements Registry<K> {
|
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) {
|
2018-09-01 06:56:57 +08:00
|
|
|
i = (int)((float)i / 0.8F);
|
|
|
|
this.b = (K[])(new Object[i]);
|
2018-07-24 00:58:01 +08:00
|
|
|
this.c = new int[i];
|
2018-09-01 06:56:57 +08:00
|
|
|
this.d = (K[])(new Object[i]);
|
2018-07-24 00:58:01 +08:00
|
|
|
+ this.usedIds = new java.util.BitSet(); // Paper
|
|
|
|
}
|
|
|
|
|
2018-09-01 06:56:57 +08:00
|
|
|
public int getId(@Nullable K object) {
|
|
|
|
@@ -41,9 +43,14 @@ public class RegistryID<K> implements Registry<K> {
|
2018-07-24 00:58:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private int c() {
|
|
|
|
+ // Paper start
|
|
|
|
+ /*
|
2018-09-01 06:56:57 +08:00
|
|
|
while(this.e < this.d.length && this.d[this.e] != null) {
|
2018-07-24 00:58:01 +08:00
|
|
|
++this.e;
|
|
|
|
}
|
|
|
|
+ */
|
|
|
|
+ this.e = this.usedIds.nextClearBit(0);
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
return this.e;
|
|
|
|
}
|
2018-09-01 06:56:57 +08:00
|
|
|
@@ -56,6 +63,7 @@ public class RegistryID<K> implements Registry<K> {
|
|
|
|
this.d = (K[])(new Object[i]);
|
2018-07-24 00:58:01 +08:00
|
|
|
this.e = 0;
|
|
|
|
this.f = 0;
|
|
|
|
+ this.usedIds.clear(); // Paper
|
|
|
|
|
2018-09-01 06:56:57 +08:00
|
|
|
for(int j = 0; j < aobject.length; ++j) {
|
2018-07-24 00:58:01 +08:00
|
|
|
if (aobject[j] != null) {
|
2018-09-01 06:56:57 +08:00
|
|
|
@@ -80,6 +88,7 @@ public class RegistryID<K> implements Registry<K> {
|
|
|
|
this.b[l] = object;
|
|
|
|
this.c[l] = i;
|
|
|
|
this.d[i] = object;
|
2018-07-24 00:58:01 +08:00
|
|
|
+ this.usedIds.set(i); // Paper
|
|
|
|
++this.f;
|
|
|
|
if (i == this.e) {
|
|
|
|
++this.e;
|
2018-09-01 06:56:57 +08:00
|
|
|
@@ -140,6 +149,7 @@ public class RegistryID<K> implements Registry<K> {
|
|
|
|
Arrays.fill(this.d, (Object)null);
|
2018-07-24 00:58:01 +08:00
|
|
|
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
|
|
|
|