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.
This commit is contained in:
parent
ca6064b775
commit
e9c7aac510
6 changed files with 27 additions and 10 deletions
|
|
@ -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
|
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
|
else
|
||||||
{
|
{
|
||||||
mob.SendMessage(
|
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."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1194,13 +1194,13 @@ public sealed class CTFGame : EventGame
|
||||||
}
|
}
|
||||||
|
|
||||||
mob.SendMessage(
|
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
|
else
|
||||||
{
|
{
|
||||||
mob.SendMessage(
|
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."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -780,13 +780,13 @@ public sealed class DDGame : EventGame
|
||||||
}
|
}
|
||||||
|
|
||||||
mob.SendMessage(
|
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
|
else
|
||||||
{
|
{
|
||||||
mob.SendMessage(
|
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."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1113,13 +1113,13 @@ public sealed class KHGame : EventGame
|
||||||
}
|
}
|
||||||
|
|
||||||
mob.SendMessage(
|
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
|
else
|
||||||
{
|
{
|
||||||
mob.SendMessage(
|
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."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -646,13 +646,13 @@ namespace Server.Engines.ConPVP
|
||||||
}
|
}
|
||||||
|
|
||||||
mob.SendMessage(
|
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
|
else
|
||||||
{
|
{
|
||||||
mob.SendMessage(
|
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."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,22 @@ public enum TrophyRank
|
||||||
Gold
|
Gold
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class TrophyRankExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a static lowercase string for the given <see cref="TrophyRank"/> value.
|
||||||
|
/// Avoids the two-allocation <c>rank.ToString().ToLower()</c> pattern at interpolation sites.
|
||||||
|
/// </summary>
|
||||||
|
public static string LowerName(this TrophyRank rank) =>
|
||||||
|
rank switch
|
||||||
|
{
|
||||||
|
TrophyRank.Bronze => "bronze",
|
||||||
|
TrophyRank.Silver => "silver",
|
||||||
|
TrophyRank.Gold => "gold",
|
||||||
|
_ => rank.ToString().ToLowerInvariant()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
[Flippable(5020, 4647)]
|
[Flippable(5020, 4647)]
|
||||||
[SerializationGenerator(2, false)]
|
[SerializationGenerator(2, false)]
|
||||||
public partial class Trophy : Item
|
public partial class Trophy : Item
|
||||||
|
|
@ -122,3 +138,4 @@ public partial class Trophy : Item
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue