Small memory optimization in Registries.

This commit is contained in:
LexManos 2016-12-16 13:01:39 -08:00
parent 1e6ae7d1f7
commit b203468cde
1 changed files with 11 additions and 1 deletions

View File

@ -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<I extends IForgeRegistryEntry<I>> extends RegistryNamespacedDefaultedByKey<ResourceLocation, I> implements IForgeRegistry<I>
{
@ -98,7 +99,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> 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<I extends IForgeRegistryEntry<I>> 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);