Address review comments.

Co-authored-by: waffle <waffle.lapkin@gmail.com>
This commit is contained in:
Mara Bos 2024-11-19 17:50:42 +00:00
parent 38b9a448c9
commit b96f023dbd

View file

@ -1,4 +1,5 @@
use crate::cell::Cell; use crate::cell::Cell;
use crate::iter;
use crate::sync::Arc; use crate::sync::Arc;
use crate::thread::Thread; use crate::thread::Thread;
@ -91,9 +92,10 @@ where
{ {
SPAWN_HOOKS.with(|h| { SPAWN_HOOKS.with(|h| {
let mut hooks = h.take(); let mut hooks = h.take();
let next = hooks.first.take();
hooks.first = Some(Arc::new(SpawnHook { hooks.first = Some(Arc::new(SpawnHook {
hook: Box::new(move |thread| Box::new(hook(thread))), hook: Box::new(move |thread| Box::new(hook(thread))),
next: hooks.first.take(), next,
})); }));
h.set(hooks); h.set(hooks);
}); });
@ -113,12 +115,9 @@ pub(super) fn run_spawn_hooks(thread: &Thread) -> ChildSpawnHooks {
snapshot snapshot
}); });
// Iterate over the hooks, run them, and collect the results in a vector. // Iterate over the hooks, run them, and collect the results in a vector.
let mut next: &Option<Arc<SpawnHook>> = &hooks.first; let to_run: Vec<_> = iter::successors(hooks.first.as_deref(), |hook| hook.next.as_deref())
let mut to_run = Vec::new(); .map(|hook| (hook.hook)(thread))
while let Some(hook) = next { .collect();
to_run.push((hook.hook)(thread));
next = &hook.next;
}
// Pass on the snapshot of the hooks and the results to the new thread, // Pass on the snapshot of the hooks and the results to the new thread,
// which will then run SpawnHookResults::run(). // which will then run SpawnHookResults::run().
ChildSpawnHooks { hooks, to_run } ChildSpawnHooks { hooks, to_run }