From 2f7f2e7bc11bd3decada05893e61b3b8291a7679 Mon Sep 17 00:00:00 2001 From: Ben Staddon Date: Tue, 1 Aug 2017 20:42:18 +0100 Subject: [PATCH] Use ClassValue to store tileentity names for profiler in lazy cache. (#4021) --- .../net/minecraft/profiler/Profiler.java.patch | 3 ++- .../net/minecraft/world/World.java.patch | 2 +- .../net/minecraftforge/common/ForgeHooks.java | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/patches/minecraft/net/minecraft/profiler/Profiler.java.patch b/patches/minecraft/net/minecraft/profiler/Profiler.java.patch index 6728ba358c..def5038660 100644 --- a/patches/minecraft/net/minecraft/profiler/Profiler.java.patch +++ b/patches/minecraft/net/minecraft/profiler/Profiler.java.patch @@ -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) diff --git a/patches/minecraft/net/minecraft/world/World.java.patch b/patches/minecraft/net/minecraft/world/World.java.patch index 40dad47224..7d319b1420 100644 --- a/patches/minecraft/net/minecraft/world/World.java.patch +++ b/patches/minecraft/net/minecraft/world/World.java.patch @@ -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(); } diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index f300ed74b3..0bbde91c74 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -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 registryNames = new ClassValue() + { + @Override + @SuppressWarnings("unchecked") + protected String computeValue(Class type) + { + return String.valueOf(TileEntity.getKey((Class) type)); + } + }; + + public static String getRegistryName(Class type) + { + return registryNames.get(type); + } + public static boolean loadAdvancements(Map map) { boolean errored = false;