Skip to content

Commit c02090d

Browse files
m-ou-seWaffleLapkin
andcommitted
Address review comments.
Co-authored-by: waffle <[email protected]>
1 parent 79bffa9 commit c02090d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

std/src/thread/spawnhook.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::cell::Cell;
2+
use crate::iter;
23
use crate::sync::Arc;
34
use crate::thread::Thread;
45

@@ -91,9 +92,10 @@ where
9192
{
9293
SPAWN_HOOKS.with(|h| {
9394
let mut hooks = h.take();
95+
let next = hooks.first.take();
9496
hooks.first = Some(Arc::new(SpawnHook {
9597
hook: Box::new(move |thread| Box::new(hook(thread))),
96-
next: hooks.first.take(),
98+
next,
9799
}));
98100
h.set(hooks);
99101
});
@@ -113,12 +115,9 @@ pub(super) fn run_spawn_hooks(thread: &Thread) -> ChildSpawnHooks {
113115
snapshot
114116
});
115117
// 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-
}
118+
let to_run: Vec<_> = iter::successors(hooks.first.as_deref(), |hook| hook.next.as_deref())
119+
.map(|hook| (hook.hook)(thread))
120+
.collect();
122121
// Pass on the snapshot of the hooks and the results to the new thread,
123122
// which will then run SpawnHookResults::run().
124123
ChildSpawnHooks { hooks, to_run }

0 commit comments

Comments
 (0)