More work on micro optimization
All checks were successful
Build / Build (push) Successful in 52s

This commit is contained in:
Deukhoofd 2025-07-05 16:13:53 +02:00
parent 8a857ed232
commit 7b25161a8d
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F

View File

@ -123,6 +123,8 @@ public static class MoveTurnExecutor
executingMove.RunScriptHookInterface<IScriptOnAfterMove>(x => x.OnAfterMove(executingMove)); executingMove.RunScriptHookInterface<IScriptOnAfterMove>(x => x.OnAfterMove(executingMove));
} }
private static readonly ThreadLocal<List<TypeIdentifier>> TypeListCache = new(() => []);
private static void ExecuteMoveChoiceForTarget(IBattle battle, IExecutingMove executingMove, IPokemon target) private static void ExecuteMoveChoiceForTarget(IBattle battle, IExecutingMove executingMove, IPokemon target)
{ {
var failed = false; var failed = false;
@ -173,7 +175,11 @@ public static class MoveTurnExecutor
hitData.Type = hitType; hitData.Type = hitType;
var types = new List<TypeIdentifier>(target.Types); // We re-use the TypeListCache to avoid allocating a new list every time.
var types = TypeListCache.Value;
types.Clear();
types.AddRange(target.Types);
executingMove.RunScriptHook(x => x.ChangeTypesForMove(executingMove, target, hitIndex, types)); executingMove.RunScriptHook(x => x.ChangeTypesForMove(executingMove, target, hitIndex, types));
target.RunScriptHook(x => x.ChangeTypesForIncomingMove(executingMove, target, hitIndex, types)); target.RunScriptHook(x => x.ChangeTypesForIncomingMove(executingMove, target, hitIndex, types));