From 048f41244f6b2c7f95ac5bf75be2b16f42b99169 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 15 May 2022 01:54:01 -0400 Subject: reduce performance impact of deprecation warnings Creating a stack is *very* slow, so it should be avoided if possible until after the duplicate-warning check. --- src/SMAPI/Framework/ContentCoordinator.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/SMAPI/Framework/ContentCoordinator.cs') diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index a24581a0..2b13f57a 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -595,6 +595,7 @@ namespace StardewModdingAPI.Framework foreach (ModLinked loader in this.Loaders) { // check if loader applies + Context.HeuristicModsRunningCode.Push(loader.Mod); try { if (!loader.Data.CanLoad(legacyInfo)) @@ -605,6 +606,10 @@ namespace StardewModdingAPI.Framework loader.Mod.LogAsMod($"Mod failed when checking whether it could load asset '{legacyInfo.Name}', and will be ignored. Error details:\n{ex.GetLogSummary()}", LogLevel.Error); continue; } + finally + { + Context.HeuristicModsRunningCode.TryPop(out _); + } // add operation group ??= new AssetOperationGroup(new List(), new List()); @@ -617,9 +622,7 @@ namespace StardewModdingAPI.Framework Mod: loader.Mod, OnBehalfOf: null, Priority: AssetLoadPriority.Exclusive, - GetData: assetInfo => loader.Data.Load( - this.GetLegacyAssetInfo(assetInfo) - ) + GetData: assetInfo => loader.Data.Load(this.GetLegacyAssetInfo(assetInfo)) ) ) ); @@ -629,6 +632,7 @@ namespace StardewModdingAPI.Framework foreach (var editor in this.Editors) { // check if editor applies + Context.HeuristicModsRunningCode.Push(editor.Mod); try { if (!editor.Data.CanEdit(legacyInfo)) @@ -639,6 +643,10 @@ namespace StardewModdingAPI.Framework editor.Mod.LogAsMod($"Mod crashed when checking whether it could edit asset '{legacyInfo.Name}', and will be ignored. Error details:\n{ex.GetLogSummary()}", LogLevel.Error); continue; } + finally + { + Context.HeuristicModsRunningCode.TryPop(out _); + } // HACK // @@ -672,9 +680,7 @@ namespace StardewModdingAPI.Framework Mod: editor.Mod, OnBehalfOf: null, Priority: priority, - ApplyEdit: assetData => editor.Data.Edit( - this.GetLegacyAssetData(assetData) - ) + ApplyEdit: assetData => editor.Data.Edit(this.GetLegacyAssetData(assetData)) ) ) ); -- cgit