From 8bd0c17431454b1799680f7d9613bb72c77e4bf2 Mon Sep 17 00:00:00 2001 From: Damian Suess Date: Mon, 5 Jan 2026 10:47:41 -0500 Subject: [PATCH] Made `ResolveNext` static so that compiler will emit nonvirtual call sites to member --- source/Lite.StateMachine/StateMachine.cs | 39 +++++++++++------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/source/Lite.StateMachine/StateMachine.cs b/source/Lite.StateMachine/StateMachine.cs index 76cf441..715d3f3 100644 --- a/source/Lite.StateMachine/StateMachine.cs +++ b/source/Lite.StateMachine/StateMachine.cs @@ -227,7 +227,7 @@ public async Task> RunAsync( if (result is null) break; - var nextId = ResolveNext(reg, result.Value); + var nextId = StateMachine.ResolveNext(reg, result.Value); if (nextId is null) break; @@ -237,6 +237,18 @@ public async Task> RunAsync( return this; } + /// Get next state transition based on state's result. + /// State registration. + /// State's returned result. + /// to go to next or NULL to bubble-up or end state machine process. + private static TStateId? ResolveNext(StateRegistration reg, Result result) => result switch + { + Result.Success => reg.OnSuccess, + Result.Error => reg.OnError, + Result.Failure => reg.OnFailure, + _ => null, + }; + /// /// Retrieves an existing state instance associated with the specified registration, /// or creates and stores a new instance if none exists. @@ -269,21 +281,6 @@ private StateRegistration GetRegistration(TStateId stateId) return reg; } - /// Get next state transition based on state's result. - /// State registration. - /// State's returned result. - /// to go to next or NULL to bubble-up or end state machine process. - private TStateId? ResolveNext(StateRegistration reg, Result result) - { - return result switch - { - Result.Success => reg.OnSuccess, - Result.Error => reg.OnError, - Result.Failure => reg.OnFailure, - _ => null, - }; - } - private async Task RunAnyStateRecursiveAsync( StateRegistration reg, PropertyBag? parameters, @@ -291,8 +288,8 @@ private StateRegistration GetRegistration(TStateId stateId) CancellationToken ct) { // Ensure we always operate on non-null, shared bags - parameters = parameters ?? []; - errors = errors ?? []; + parameters ??= []; + errors ??= []; // Run Normal or Command State if (!reg.IsCompositeParent) @@ -362,7 +359,7 @@ private StateRegistration GetRegistration(TStateId stateId) // TODO (#76): Extract the Context.OnSuccess/Error/Failure override (if any) lastChildResult = childResult; - var nextChildId = ResolveNext(childReg, childResult.Value); + var nextChildId = StateMachine.ResolveNext(childReg, childResult.Value); // NULL mapping => last child => bubble-up to parent and exit if (nextChildId is null) @@ -396,13 +393,13 @@ private StateRegistration GetRegistration(TStateId stateId) { if (parameters is not null) { - foreach (string k in parameters.Keys) + foreach (var k in parameters.Keys) if (!originalParamKeys.Contains(k)) parameters.Remove(k); } if (errors is not null) { - foreach (string k in errors.Keys) + foreach (var k in errors.Keys) if (!originalErrorKeys.Contains(k)) errors.Remove(k); } }