From 5fd9e7fa3dcbfd1b3198dafa6fc4b51915ea11d0 Mon Sep 17 00:00:00 2001 From: Kenth Eriksson Date: Thu, 19 Nov 2026 09:38:50 +0000 Subject: [PATCH] efficiency: dispatch regions in a loop in process_event_impl process_event_impl unrolls one dispatch call per orthogonal region. Every region uses the same dispatch table, so a loop over current_state_ keeps one call site and drops the fold-expression branch. Clang 19.1.7, -Oz, -mcpu=cortex-a53, one machine with three regions: the translation unit that instantiates it shrank by 992 bytes. --- include/boost/sml.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/include/boost/sml.hpp b/include/boost/sml.hpp index 741effd8..622d7dfa 100644 --- a/include/boost/sml.hpp +++ b/include/boost/sml.hpp @@ -2280,13 +2280,9 @@ struct sm_impl : aux::conditional_t &states, aux::index_sequence) { auto handled = false; -#if defined(__cpp_fold_expressions) - ((handled |= dispatch_t::template dispatch<0, TMappings>(*this, current_state_[Ns], event, d, subs, states)), ...); -#else - (void)aux::swallow{ - 0, - (handled |= dispatch_t::template dispatch<0, TMappings>(*this, current_state_[Ns], event, d, subs, states), 0)...}; -#endif + for (auto i = 0u; i < sizeof...(Ns); ++i) { + handled |= dispatch_t::template dispatch<0, TMappings>(*this, current_state_[i], event, d, subs, states); + } return handled; } template