From b203468cde953bbd35b4043fa8ebff4364f1f8d9 Mon Sep 17 00:00:00 2001 From: LexManos Date: Fri, 16 Dec 2016 13:01:39 -0800 Subject: [PATCH] Small memory optimization in Registries. --- .../registry/FMLControlledNamespacedRegistry.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java index 5a9e5a0bf..5b874d2cf 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java @@ -45,6 +45,7 @@ import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey; import net.minecraftforge.fml.common.FMLLog; import net.minecraftforge.fml.common.functions.GenericIterableFactory; import net.minecraftforge.fml.common.registry.RegistryDelegate.Delegate; +import net.minecraftforge.fml.relauncher.ReflectionHelper; public class FMLControlledNamespacedRegistry> extends RegistryNamespacedDefaultedByKey implements IForgeRegistry { @@ -98,7 +99,7 @@ public class FMLControlledNamespacedRegistry> e this.optionalDefaultKey = defaultKey; this.minId = minIdValue; this.maxId = maxIdValue; - this.availabilityMap = new BitSet(maxIdValue + 1); + this.availabilityMap = new BitSet(Math.min(maxIdValue + 1, 0xFFFF)); //No need to pre-allocate large sets, it will resize when we need it. this.isDelegated = IForgeRegistryEntry.Impl.class.isAssignableFrom(type); this.addCallback = addCallback; this.clearCallback = clearCallback; @@ -112,6 +113,15 @@ public class FMLControlledNamespacedRegistry> e void validateContent(ResourceLocation registryName) { + try + { + ReflectionHelper.findMethod(BitSet.class, this.availabilityMap, new String[]{"trimToSize"}).invoke(this.availabilityMap); + } + catch (Exception e) + { + //We don't care... Just a micro-optimization + } + for (I obj : typeSafeIterable()) { int id = getId(obj);