From e9c7aac510f158d81b207767005343914edb8124 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 3 May 2026 18:31:40 -0700 Subject: [PATCH] perf(conpvp): zero-alloc trophy text via TrophyRank.LowerName (#2438) ## Summary Phase 3.3 of the message-interpolation cleanup. Eliminates the `rank.ToString().ToLower()` two-allocation pattern in ConPVP trophy-award messages. - Adds `TrophyRank.LowerName()` extension returning a static lowercase string per enum value via switch expression. - Updates 10 call sites across Tournament, KingOfTheHill, DoubleDom, CTF, BombingRun (2 each - cash and no-cash branches). The handler now appends a static interned string directly into the packet buffer; no `ToString()` formatter and no `ToLower()` allocation per call. Source comment in BombingRun.cs ("There is no formatting flag for Lowercase, we may need a custom interface to get rid of it") is now resolved at the call-site level. --- .../Engines/ConPVP/Games/BombingRun.cs | 4 ++-- Projects/UOContent/Engines/ConPVP/Games/CTF.cs | 4 ++-- .../UOContent/Engines/ConPVP/Games/DoubleDom.cs | 4 ++-- .../Engines/ConPVP/Games/KingOfTheHill.cs | 4 ++-- Projects/UOContent/Engines/ConPVP/Tournament.cs | 4 ++-- Projects/UOContent/Engines/ConPVP/Trophy.cs | 17 +++++++++++++++++ 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Projects/UOContent/Engines/ConPVP/Games/BombingRun.cs b/Projects/UOContent/Engines/ConPVP/Games/BombingRun.cs index 489efff71..29e0b9949 100644 --- a/Projects/UOContent/Engines/ConPVP/Games/BombingRun.cs +++ b/Projects/UOContent/Engines/ConPVP/Games/BombingRun.cs @@ -1813,13 +1813,13 @@ public sealed class BRGame : EventGame } mob.SendMessage( //There is no formatting flag for Lowercase, we may need a custom interface to get rid of it - $"You have been awarded a {rank.ToString().ToLower()} trophy and {cash:N0}gp for your participation in this tournament." + $"You have been awarded a {rank.LowerName()} trophy and {cash:N0}gp for your participation in this tournament." ); } else { mob.SendMessage( - $"You have been awarded a {rank.ToString().ToLower()} trophy for your participation in this tournament." + $"You have been awarded a {rank.LowerName()} trophy for your participation in this tournament." ); } } diff --git a/Projects/UOContent/Engines/ConPVP/Games/CTF.cs b/Projects/UOContent/Engines/ConPVP/Games/CTF.cs index 2a0326ef3..d9e879820 100644 --- a/Projects/UOContent/Engines/ConPVP/Games/CTF.cs +++ b/Projects/UOContent/Engines/ConPVP/Games/CTF.cs @@ -1194,13 +1194,13 @@ public sealed class CTFGame : EventGame } mob.SendMessage( - $"You have been awarded a {rank.ToString().ToLower()} trophy and {cash:N0}gp for your participation in this tournament." + $"You have been awarded a {rank.LowerName()} trophy and {cash:N0}gp for your participation in this tournament." ); } else { mob.SendMessage( - $"You have been awarded a {rank.ToString().ToLower()} trophy for your participation in this tournament." + $"You have been awarded a {rank.LowerName()} trophy for your participation in this tournament." ); } } diff --git a/Projects/UOContent/Engines/ConPVP/Games/DoubleDom.cs b/Projects/UOContent/Engines/ConPVP/Games/DoubleDom.cs index 73897404e..b53cc33cb 100644 --- a/Projects/UOContent/Engines/ConPVP/Games/DoubleDom.cs +++ b/Projects/UOContent/Engines/ConPVP/Games/DoubleDom.cs @@ -780,13 +780,13 @@ public sealed class DDGame : EventGame } mob.SendMessage( - $"You have been awarded a {rank.ToString().ToLower()} trophy and {cash:N0}gp for your participation in this tournament." + $"You have been awarded a {rank.LowerName()} trophy and {cash:N0}gp for your participation in this tournament." ); } else { mob.SendMessage( - $"You have been awarded a {rank.ToString().ToLower()} trophy for your participation in this tournament." + $"You have been awarded a {rank.LowerName()} trophy for your participation in this tournament." ); } } diff --git a/Projects/UOContent/Engines/ConPVP/Games/KingOfTheHill.cs b/Projects/UOContent/Engines/ConPVP/Games/KingOfTheHill.cs index 43ae9c4b6..6f73a0949 100644 --- a/Projects/UOContent/Engines/ConPVP/Games/KingOfTheHill.cs +++ b/Projects/UOContent/Engines/ConPVP/Games/KingOfTheHill.cs @@ -1113,13 +1113,13 @@ public sealed class KHGame : EventGame } mob.SendMessage( - $"You have been awarded a {rank.ToString().ToLower()} trophy and {cash:N0}gp for your participation in this game." + $"You have been awarded a {rank.LowerName()} trophy and {cash:N0}gp for your participation in this game." ); } else { mob.SendMessage( - $"You have been awarded a {rank.ToString().ToLower()} trophy for your participation in this game." + $"You have been awarded a {rank.LowerName()} trophy for your participation in this game." ); } } diff --git a/Projects/UOContent/Engines/ConPVP/Tournament.cs b/Projects/UOContent/Engines/ConPVP/Tournament.cs index 82b9b8d9d..e0be60c6f 100644 --- a/Projects/UOContent/Engines/ConPVP/Tournament.cs +++ b/Projects/UOContent/Engines/ConPVP/Tournament.cs @@ -646,13 +646,13 @@ namespace Server.Engines.ConPVP } mob.SendMessage( - $"You have been awarded a {rank.ToString().ToLower()} trophy and {cash:N0}gp for your participation in this tournament." + $"You have been awarded a {rank.LowerName()} trophy and {cash:N0}gp for your participation in this tournament." ); } else { mob.SendMessage( - $"You have been awarded a {rank.ToString().ToLower()} trophy for your participation in this tournament." + $"You have been awarded a {rank.LowerName()} trophy for your participation in this tournament." ); } } diff --git a/Projects/UOContent/Engines/ConPVP/Trophy.cs b/Projects/UOContent/Engines/ConPVP/Trophy.cs index 56e92daf3..fa712de33 100644 --- a/Projects/UOContent/Engines/ConPVP/Trophy.cs +++ b/Projects/UOContent/Engines/ConPVP/Trophy.cs @@ -10,6 +10,22 @@ public enum TrophyRank Gold } +public static class TrophyRankExtensions +{ + /// + /// Returns a static lowercase string for the given value. + /// Avoids the two-allocation rank.ToString().ToLower() pattern at interpolation sites. + /// + public static string LowerName(this TrophyRank rank) => + rank switch + { + TrophyRank.Bronze => "bronze", + TrophyRank.Silver => "silver", + TrophyRank.Gold => "gold", + _ => rank.ToString().ToLowerInvariant() + }; +} + [Flippable(5020, 4647)] [SerializationGenerator(2, false)] public partial class Trophy : Item @@ -122,3 +138,4 @@ public partial class Trophy : Item }; } } +