From 7c90385d8df7bbf9469fc468480b26ebb134abd8 Mon Sep 17 00:00:00 2001
From: atravita-mods <94934860+atravita-mods@users.noreply.github.com>
Date: Mon, 15 Aug 2022 19:13:24 -0400
Subject: Pre-calculate the strings for log levels.
---
src/SMAPI/Framework/Monitor.cs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'src/SMAPI/Framework/Monitor.cs')
diff --git a/src/SMAPI/Framework/Monitor.cs b/src/SMAPI/Framework/Monitor.cs
index 6b53daff..8ba175e6 100644
--- a/src/SMAPI/Framework/Monitor.cs
+++ b/src/SMAPI/Framework/Monitor.cs
@@ -25,7 +25,9 @@ namespace StardewModdingAPI.Framework
private readonly LogFileManager LogFile;
/// The maximum length of the values.
- private static readonly int MaxLevelLength = (from level in Enum.GetValues(typeof(LogLevel)).Cast() select level.ToString().Length).Max();
+ private static readonly int MaxLevelLength = (from level in Enum.GetValues() select level.ToString().Length).Max();
+
+ private static readonly Dictionary LogStrings = Enum.GetValues().ToDictionary(k => k, v => v.ToString().ToUpper().PadRight(MaxLevelLength));
/// A cache of messages that should only be logged once.
private readonly HashSet LogOnceCache = new();
@@ -147,7 +149,7 @@ namespace StardewModdingAPI.Framework
/// The log level.
private string GenerateMessagePrefix(string source, ConsoleLogLevel level)
{
- string levelStr = level.ToString().ToUpper().PadRight(Monitor.MaxLevelLength);
+ string levelStr = LogStrings[level];
int? playerIndex = this.GetScreenIdForLog();
return $"[{DateTime.Now:HH:mm:ss} {levelStr}{(playerIndex != null ? $" screen_{playerIndex}" : "")} {source}]";
--
cgit
From 4a1055e573e9d8b0aa654238889596be07c29193 Mon Sep 17 00:00:00 2001
From: atravita-mods <94934860+atravita-mods@users.noreply.github.com>
Date: Tue, 16 Aug 2022 15:30:21 -0400
Subject: arraypool in the modcontentmanager, a bit of fussing
---
src/SMAPI/Framework/Monitor.cs | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
(limited to 'src/SMAPI/Framework/Monitor.cs')
diff --git a/src/SMAPI/Framework/Monitor.cs b/src/SMAPI/Framework/Monitor.cs
index 8ba175e6..d33bf259 100644
--- a/src/SMAPI/Framework/Monitor.cs
+++ b/src/SMAPI/Framework/Monitor.cs
@@ -27,10 +27,13 @@ namespace StardewModdingAPI.Framework
/// The maximum length of the values.
private static readonly int MaxLevelLength = (from level in Enum.GetValues() select level.ToString().Length).Max();
+ /// A mapping of console log levels to their string form.
private static readonly Dictionary LogStrings = Enum.GetValues().ToDictionary(k => k, v => v.ToString().ToUpper().PadRight(MaxLevelLength));
+ private readonly record struct LogOnceCacheEntry(string message, LogLevel level);
+
/// A cache of messages that should only be logged once.
- private readonly HashSet LogOnceCache = new();
+ private readonly HashSet LogOnceCache = new();
/// Get the screen ID that should be logged to distinguish between players in split-screen mode, if any.
private readonly Func GetScreenIdForLog;
@@ -86,7 +89,7 @@ namespace StardewModdingAPI.Framework
///
public void LogOnce(string message, LogLevel level = LogLevel.Trace)
{
- if (this.LogOnceCache.Add($"{message}|{level}"))
+ if (this.LogOnceCache.Add(new LogOnceCacheEntry(message, level)))
this.LogImpl(this.Source, message, (ConsoleLogLevel)level);
}
--
cgit
From 2e0bc5ddfe90102fe5adbc90b2d53c5cbb8405fe Mon Sep 17 00:00:00 2001
From: Jesse Plamondon-Willard
Date: Sat, 8 Oct 2022 17:45:50 -0400
Subject: tweak new code
---
src/SMAPI/Framework/Monitor.cs | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
(limited to 'src/SMAPI/Framework/Monitor.cs')
diff --git a/src/SMAPI/Framework/Monitor.cs b/src/SMAPI/Framework/Monitor.cs
index d33bf259..4ed2c9bb 100644
--- a/src/SMAPI/Framework/Monitor.cs
+++ b/src/SMAPI/Framework/Monitor.cs
@@ -25,15 +25,13 @@ namespace StardewModdingAPI.Framework
private readonly LogFileManager LogFile;
/// The maximum length of the values.
- private static readonly int MaxLevelLength = (from level in Enum.GetValues() select level.ToString().Length).Max();
+ private static readonly int MaxLevelLength = Enum.GetValues().Max(level => level.ToString().Length);
- /// A mapping of console log levels to their string form.
- private static readonly Dictionary LogStrings = Enum.GetValues().ToDictionary(k => k, v => v.ToString().ToUpper().PadRight(MaxLevelLength));
-
- private readonly record struct LogOnceCacheEntry(string message, LogLevel level);
+ /// The cached representation for each level when added to a log header.
+ private static readonly Dictionary LogStrings = Enum.GetValues().ToDictionary(level => level, level => level.ToString().ToUpper().PadRight(Monitor.MaxLevelLength));
/// A cache of messages that should only be logged once.
- private readonly HashSet LogOnceCache = new();
+ private readonly HashSet LogOnceCache = new();
/// Get the screen ID that should be logged to distinguish between players in split-screen mode, if any.
private readonly Func GetScreenIdForLog;
@@ -89,7 +87,7 @@ namespace StardewModdingAPI.Framework
///
public void LogOnce(string message, LogLevel level = LogLevel.Trace)
{
- if (this.LogOnceCache.Add(new LogOnceCacheEntry(message, level)))
+ if (this.LogOnceCache.Add(new LogOnceCacheKey(message, level)))
this.LogImpl(this.Source, message, (ConsoleLogLevel)level);
}
@@ -152,7 +150,7 @@ namespace StardewModdingAPI.Framework
/// The log level.
private string GenerateMessagePrefix(string source, ConsoleLogLevel level)
{
- string levelStr = LogStrings[level];
+ string levelStr = Monitor.LogStrings[level];
int? playerIndex = this.GetScreenIdForLog();
return $"[{DateTime.Now:HH:mm:ss} {levelStr}{(playerIndex != null ? $" screen_{playerIndex}" : "")} {source}]";
--
cgit