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/Content/AssetInfo.cs | 4 ++-- src/SMAPI/Framework/Content/AssetInterceptorChange.cs | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src/SMAPI/Framework/Content') diff --git a/src/SMAPI/Framework/Content/AssetInfo.cs b/src/SMAPI/Framework/Content/AssetInfo.cs index a4f0a408..773e3126 100644 --- a/src/SMAPI/Framework/Content/AssetInfo.cs +++ b/src/SMAPI/Framework/Content/AssetInfo.cs @@ -36,7 +36,7 @@ namespace StardewModdingAPI.Framework.Content get { SCore.DeprecationManager.Warn( - source: SCore.DeprecationManager.GetModFromStack(), + source: null, nounPhrase: $"{nameof(IAssetInfo)}.{nameof(IAssetInfo.AssetName)}", version: "3.14.0", severity: DeprecationLevel.Notice, @@ -76,7 +76,7 @@ namespace StardewModdingAPI.Framework.Content public bool AssetNameEquals(string path) { SCore.DeprecationManager.Warn( - source: SCore.DeprecationManager.GetModFromStack(), + source: null, nounPhrase: $"{nameof(IAssetInfo)}.{nameof(IAssetInfo.AssetNameEquals)}", version: "3.14.0", severity: DeprecationLevel.Notice, diff --git a/src/SMAPI/Framework/Content/AssetInterceptorChange.cs b/src/SMAPI/Framework/Content/AssetInterceptorChange.cs index fc8199e8..f3d4f3f4 100644 --- a/src/SMAPI/Framework/Content/AssetInterceptorChange.cs +++ b/src/SMAPI/Framework/Content/AssetInterceptorChange.cs @@ -64,6 +64,7 @@ namespace StardewModdingAPI.Framework.Content // check edit if (this.Instance is IAssetEditor editor) { + Context.HeuristicModsRunningCode.Push(this.Mod); try { if (editor.CanEdit(asset)) @@ -73,11 +74,16 @@ namespace StardewModdingAPI.Framework.Content { this.Mod.LogAsMod($"Mod failed when checking whether it could edit asset '{asset.Name}'. Error details:\n{ex.GetLogSummary()}", LogLevel.Error); } + finally + { + Context.HeuristicModsRunningCode.TryPop(out _); + } } // check load if (this.Instance is IAssetLoader loader) { + Context.HeuristicModsRunningCode.Push(this.Mod); try { if (loader.CanLoad(asset)) @@ -87,6 +93,10 @@ namespace StardewModdingAPI.Framework.Content { this.Mod.LogAsMod($"Mod failed when checking whether it could load asset '{asset.Name}'. Error details:\n{ex.GetLogSummary()}", LogLevel.Error); } + finally + { + Context.HeuristicModsRunningCode.TryPop(out _); + } } return false; -- cgit