Use ClassValue to store tileentity names for profiler in lazy cache. (#4021)

This commit is contained in:
Ben Staddon 2017-08-01 20:42:18 +01:00 committed by LexManos
parent 2d97f05796
commit 2f7f2e7bc1
3 changed files with 18 additions and 2 deletions

View File

@ -1,6 +1,6 @@
--- ../src-base/minecraft/net/minecraft/profiler/Profiler.java
+++ ../src-work/minecraft/net/minecraft/profiler/Profiler.java
@@ -177,4 +177,15 @@
@@ -177,4 +177,16 @@
return (this.field_76331_c.hashCode() & 11184810) + 4473924;
}
}
@ -8,6 +8,7 @@
+ /**
+ * Forge: Fix for MC-117087, World.updateEntities is wasting time calling Class.getSimpleName() when the profiler is not active
+ */
+ @Deprecated // TODO: remove (1.13)
+ public void startSection(Class<?> profiledClass)
+ {
+ if (this.field_76327_a)

View File

@ -415,7 +415,7 @@
try
{
- this.field_72984_F.func_76320_a(tileentity.getClass().getSimpleName());
+ this.field_72984_F.startSection(tileentity.getClass()); // Fix for MC-117087
+ this.field_72984_F.func_76320_a(this.field_72984_F.field_76327_a ? net.minecraftforge.common.ForgeHooks.getRegistryName(tileentity.getClass()) : ""); // Fix for MC-117087
((ITickable)tileentity).func_73660_a();
this.field_72984_F.func_76319_b();
}

View File

@ -1247,6 +1247,21 @@ public class ForgeHooks
MinecraftForge.EVENT_BUS.post(new BlockEvent.CropGrowEvent.Post(worldIn, pos, state, worldIn.getBlockState(pos)));
}
private static final ClassValue<String> registryNames = new ClassValue<String>()
{
@Override
@SuppressWarnings("unchecked")
protected String computeValue(Class<?> type)
{
return String.valueOf(TileEntity.getKey((Class<? extends TileEntity>) type));
}
};
public static String getRegistryName(Class<? extends TileEntity> type)
{
return registryNames.get(type);
}
public static boolean loadAdvancements(Map<ResourceLocation, Advancement.Builder> map)
{
boolean errored = false;