2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-07-23 18:58:01 +02:00
|
|
|
From: Andrew Steinborn <git@steinborn.me>
|
2018-07-23 19:10:06 +02:00
|
|
|
Date: Mon, 23 Jul 2018 13:08:19 -0400
|
2018-07-23 18:58:01 +02:00
|
|
|
Subject: [PATCH] Optimize RegistryID.c()
|
|
|
|
|
|
|
|
This is a frequent hotspot for world loading/saving.
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/util/RegistryID.java b/src/main/java/net/minecraft/util/RegistryID.java
|
|
|
|
index 6150f7a5c5004ac79414ab22dbaa3439dc8afdb4..a59dbfa01743137702b122f73c778452e63115b5 100644
|
|
|
|
--- a/src/main/java/net/minecraft/util/RegistryID.java
|
|
|
|
+++ b/src/main/java/net/minecraft/util/RegistryID.java
|
|
|
|
@@ -15,12 +15,14 @@ public class RegistryID<K> implements Registry<K> {
|
2018-07-23 18:58:01 +02:00
|
|
|
private K[] d;
|
|
|
|
private int e;
|
|
|
|
private int f;
|
|
|
|
+ private java.util.BitSet usedIds; // Paper
|
|
|
|
|
|
|
|
public RegistryID(int i) {
|
2019-01-01 04:15:55 +01:00
|
|
|
i = (int) ((float) i / 0.8F);
|
|
|
|
this.b = (K[]) (new Object[i]); // Paper - decompile fix
|
2018-07-23 18:58:01 +02:00
|
|
|
this.c = new int[i];
|
2019-01-01 04:15:55 +01:00
|
|
|
this.d = (K[]) (new Object[i]); // Paper - decompile fix
|
2018-07-23 18:58:01 +02:00
|
|
|
+ this.usedIds = new java.util.BitSet(); // Paper
|
|
|
|
}
|
|
|
|
|
2020-08-25 04:22:08 +02:00
|
|
|
// Paper start - decompile fix
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -52,9 +54,14 @@ public class RegistryID<K> implements Registry<K> {
|
2018-07-23 18:58:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private int c() {
|
|
|
|
+ // Paper start
|
|
|
|
+ /*
|
2019-01-01 04:15:55 +01:00
|
|
|
while (this.e < this.d.length && this.d[this.e] != null) {
|
2018-07-23 18:58:01 +02:00
|
|
|
++this.e;
|
|
|
|
}
|
|
|
|
+ */
|
|
|
|
+ this.e = this.usedIds.nextClearBit(0);
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
return this.e;
|
|
|
|
}
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -68,6 +75,7 @@ public class RegistryID<K> implements Registry<K> {
|
2019-01-01 04:15:55 +01:00
|
|
|
this.d = (K[]) (new Object[i]); // Paper - decompile fix
|
2018-07-23 18:58:01 +02:00
|
|
|
this.e = 0;
|
|
|
|
this.f = 0;
|
|
|
|
+ this.usedIds.clear(); // Paper
|
|
|
|
|
2019-01-01 04:15:55 +01:00
|
|
|
for (int j = 0; j < ak.length; ++j) {
|
|
|
|
if (ak[j] != null) {
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -93,6 +101,7 @@ public class RegistryID<K> implements Registry<K> {
|
2019-01-01 04:15:55 +01:00
|
|
|
this.b[k] = k0;
|
|
|
|
this.c[k] = i;
|
|
|
|
this.d[i] = k0;
|
2018-07-23 18:58:01 +02:00
|
|
|
+ this.usedIds.set(i); // Paper
|
|
|
|
++this.f;
|
|
|
|
if (i == this.e) {
|
|
|
|
++this.e;
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -157,6 +166,7 @@ public class RegistryID<K> implements Registry<K> {
|
2019-01-01 04:15:55 +01:00
|
|
|
Arrays.fill(this.d, (Object) null);
|
2018-07-23 18:58:01 +02:00
|
|
|
this.e = 0;
|
|
|
|
this.f = 0;
|
|
|
|
+ this.usedIds.clear(); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public int b() {
|