Skip to content

Commit 706106f

Browse files
m-ou-seWaffleLapkin
andcommitted
Address review comments.
Co-authored-by: waffle <[email protected]>
1 parent 38b9a44 commit 706106f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

library/std/src/thread/spawnhook.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ where
9191
{
9292
SPAWN_HOOKS.with(|h| {
9393
let mut hooks = h.take();
94+
let next = hooks.first.take();
9495
hooks.first = Some(Arc::new(SpawnHook {
9596
hook: Box::new(move |thread| Box::new(hook(thread))),
96-
next: hooks.first.take(),
97+
next,
9798
}));
9899
h.set(hooks);
99100
});
@@ -113,12 +114,9 @@ pub(super) fn run_spawn_hooks(thread: &Thread) -> ChildSpawnHooks {
113114
snapshot
114115
});
115116
// Iterate over the hooks, run them, and collect the results in a vector.
116-
let mut next: &Option<Arc<SpawnHook>> = &hooks.first;
117-
let mut to_run = Vec::new();
118-
while let Some(hook) = next {
119-
to_run.push((hook.hook)(thread));
120-
next = &hook.next;
121-
}
117+
let to_run: Vec<_> = std::iter::successors(hooks.first.as_deref(), |hook| hook.next.as_deref())
118+
.map(|hook| (hook.hook)(thread))
119+
.collect();
122120
// Pass on the snapshot of the hooks and the results to the new thread,
123121
// which will then run SpawnHookResults::run().
124122
ChildSpawnHooks { hooks, to_run }

0 commit comments

Comments
 (0)