11import DataStructures
2+ import Base. Cartesian: @nexprs
23
34"""
45 DistributedODEIntegrator <: AbstractODEIntegrator
@@ -226,14 +227,13 @@ reached_tstop(integrator, tstop, stop_at_tstop = integrator.dtchangeable) =
226227 integrator. t == tstop || (! stop_at_tstop && is_past_t (integrator, tstop))
227228
228229
229- @inline unrolled_foreach (:: Tuple{} , integrator) = nothing
230- @inline unrolled_foreach (callback, integrator) =
231- callback. condition (integrator. u, integrator. t, integrator) ? callback. affect! (integrator) : nothing
232- @inline unrolled_foreach (discrete_callbacks:: Tuple{Any} , integrator) =
233- unrolled_foreach (first (discrete_callbacks), integrator)
234- @inline function unrolled_foreach (discrete_callbacks:: Tuple , integrator)
235- unrolled_foreach (first (discrete_callbacks), integrator)
236- unrolled_foreach (Base. tail (discrete_callbacks), integrator)
230+ @generated function unrolled_foreach (:: Val{N} , callbacks, integrator) where {N}
231+ return quote
232+ @nexprs $ N i -> begin
233+ callback = callbacks[i]
234+ callback. condition (integrator. u, integrator. t, integrator) ? callback. affect! (integrator) : nothing
235+ end
236+ end
237237end
238238
239239function __step! (integrator)
@@ -257,7 +257,7 @@ function __step!(integrator)
257257
258258 # apply callbacks
259259 discrete_callbacks = integrator. callback. discrete_callbacks
260- unrolled_foreach (discrete_callbacks, integrator)
260+ unrolled_foreach (Val ( length (discrete_callbacks)), discrete_callbacks, integrator)
261261
262262 # remove tstops that were just reached
263263 while ! isempty (tstops) && reached_tstop (integrator, first (tstops))
0 commit comments