From 47da466c45f49d27985f62fea0fc844f4d99d9c8 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Jan 2026 16:26:26 -0500 Subject: [PATCH] Reduce memory allocations in PingTrackerPatch.cs --- Reactor/Patches/Miscellaneous/PingTrackerPatch.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Reactor/Patches/Miscellaneous/PingTrackerPatch.cs b/Reactor/Patches/Miscellaneous/PingTrackerPatch.cs index 0662758..c530b1d 100644 --- a/Reactor/Patches/Miscellaneous/PingTrackerPatch.cs +++ b/Reactor/Patches/Miscellaneous/PingTrackerPatch.cs @@ -7,15 +7,22 @@ namespace Reactor.Patches.Miscellaneous; [HarmonyPatch(typeof(PingTracker), nameof(PingTracker.Update))] internal static class PingTrackerPatch { + private static string? _extraText; + private static string? ExtraText => _extraText ??= ReactorCredits.GetText(ReactorCredits.Location.PingTracker); + [HarmonyPostfix] [HarmonyPriority(Priority.Last)] public static void Postfix(PingTracker __instance) { - var extraText = ReactorCredits.GetText(ReactorCredits.Location.PingTracker); - if (extraText != null) + if (ExtraText == null) + { + return; + } + + if (!__instance.text.text.EndsWith("\n", StringComparison.InvariantCulture)) { - if (!__instance.text.text.EndsWith("\n", StringComparison.InvariantCulture)) __instance.text.text += "\n"; - __instance.text.text += extraText; + __instance.text.text += "\n"; } + __instance.text.text += ExtraText; } }