Cache resource keys instead of trying to create them (#7643)
This commit is contained in:
@@ -34,6 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import java.util.Map;
|
||||
+import java.util.Objects;
|
||||
+import java.util.Optional;
|
||||
+import java.util.concurrent.ConcurrentHashMap;
|
||||
+import java.util.function.Supplier;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
@@ -49,7 +50,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ private boolean registered;
|
||||
+ private final RegistryKey<API, MINECRAFT> registryKey;
|
||||
+ private final Supplier<Registry<MINECRAFT>> registry;
|
||||
+ private final Map<NamespacedKey, API> cache = new HashMap<>();
|
||||
+ private final Map<NamespacedKey, API> cache = new ConcurrentHashMap<>();
|
||||
+ private final Map<NamespacedKey, ResourceKey<MINECRAFT>> resourceKeyCache = new ConcurrentHashMap<>();
|
||||
+
|
||||
+ public PaperRegistry(RegistryKey<API, MINECRAFT> registryKey) {
|
||||
+ this.registryKey = registryKey;
|
||||
@@ -93,7 +95,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+
|
||||
+ public Holder<MINECRAFT> getMinecraftHolder(API apiValue) {
|
||||
+ return this.registry.get().getHolderOrThrow(ResourceKey.create(this.registryKey.resourceKey(), CraftNamespacedKey.toMinecraft(apiValue.getKey())));
|
||||
+ return this.registry.get().getHolderOrThrow(this.resourceKeyCache.computeIfAbsent(apiValue.getKey(), key -> ResourceKey.create(this.registryKey.resourceKey(), CraftNamespacedKey.toMinecraft(key))));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
|
||||
Reference in New Issue
Block a user