summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/SCore.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-05-15 01:54:01 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-05-15 01:54:01 -0400
commit048f41244f6b2c7f95ac5bf75be2b16f42b99169 (patch)
tree59f6937d63653a7cb3ec04fde9f76539429a7854 /src/SMAPI/Framework/SCore.cs
parent3a4758dfa63f0f8e03166bffa15e16f7995499d7 (diff)
downloadSMAPI-048f41244f6b2c7f95ac5bf75be2b16f42b99169.tar.gz
SMAPI-048f41244f6b2c7f95ac5bf75be2b16f42b99169.tar.bz2
SMAPI-048f41244f6b2c7f95ac5bf75be2b16f42b99169.zip
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.
Diffstat (limited to 'src/SMAPI/Framework/SCore.cs')
-rw-r--r--src/SMAPI/Framework/SCore.cs18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index 5ae4fdbb..7042e83a 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -1677,6 +1677,7 @@ namespace StardewModdingAPI.Framework
#pragma warning restore CS0612, CS0618
// call entry method
+ Context.HeuristicModsRunningCode.Push(metadata);
try
{
IMod mod = metadata.Mod!;
@@ -1705,6 +1706,7 @@ namespace StardewModdingAPI.Framework
{
this.Monitor.Log($"Failed loading mod-provided API for {metadata.DisplayName}. Integrations with other mods may not work. Error: {ex.GetLogSummary()}", LogLevel.Error);
}
+ Context.HeuristicModsRunningCode.TryPop(out _);
}
// unlock mod integrations
@@ -1852,7 +1854,7 @@ namespace StardewModdingAPI.Framework
try
{
// get mod instance
- if (!this.TryLoadModEntry(modAssembly, out Mod? modEntry, out errorReasonPhrase))
+ if (!this.TryLoadModEntry(mod, modAssembly, out Mod? modEntry, out errorReasonPhrase))
{
failReason = ModFailReason.LoadFailed;
return false;
@@ -1954,11 +1956,12 @@ namespace StardewModdingAPI.Framework
}
/// <summary>Load a mod's entry class.</summary>
+ /// <param name="metadata">The mod metadata whose entry class is being loaded.</param>
/// <param name="modAssembly">The mod assembly.</param>
/// <param name="mod">The loaded instance.</param>
/// <param name="error">The error indicating why loading failed (if applicable).</param>
/// <returns>Returns whether the mod entry class was successfully loaded.</returns>
- private bool TryLoadModEntry(Assembly modAssembly, [NotNullWhen(true)] out Mod? mod, [NotNullWhen(false)] out string? error)
+ private bool TryLoadModEntry(IModMetadata metadata, Assembly modAssembly, [NotNullWhen(true)] out Mod? mod, [NotNullWhen(false)] out string? error)
{
mod = null;
@@ -1976,7 +1979,16 @@ namespace StardewModdingAPI.Framework
}
// get implementation
- mod = (Mod?)modAssembly.CreateInstance(modEntries[0].ToString());
+ Context.HeuristicModsRunningCode.Push(metadata);
+ try
+ {
+ mod = (Mod?)modAssembly.CreateInstance(modEntries[0].ToString());
+ }
+ finally
+ {
+ Context.HeuristicModsRunningCode.TryPop(out _);
+ }
+
if (mod == null)
{
error = "its entry class couldn't be instantiated.";