@@ -225,6 +225,17 @@ is_past_t(integrator, t) = tdir(integrator) * (t - integrator.t) < zero(integrat
225225reached_tstop (integrator, tstop, stop_at_tstop = integrator. dtchangeable) =
226226 integrator. t == tstop || (! stop_at_tstop && is_past_t (integrator, tstop))
227227
228+
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)
237+ end
238+
228239function __step! (integrator)
229240 (; _dt, dtchangeable, tstops) = integrator
230241
@@ -246,13 +257,7 @@ function __step!(integrator)
246257
247258 # apply callbacks
248259 discrete_callbacks = integrator. callback. discrete_callbacks
249- for (ncb, callback) in enumerate (discrete_callbacks)
250- if callback. condition (integrator. u, integrator. t, integrator):: Bool
251- NVTX. @range " Callback $ncb of $(length (discrete_callbacks)) " color = colorant " yellow" begin
252- callback. affect! (integrator)
253- end
254- end
255- end
260+ unrolled_foreach (discrete_callbacks, integrator)
256261
257262 # remove tstops that were just reached
258263 while ! isempty (tstops) && reached_tstop (integrator, first (tstops))
0 commit comments