Commit 9ff61b82 authored by Matt Mastracci's avatar Matt Mastracci

Reduce unnecessary clones

parent 86fd4ea1
use std::{collections::hash_map::Entry, fmt::Display, future::Future, mem::take, sync::Arc}; use std::{collections::hash_map::Entry, fmt::Display, future::Future, sync::Arc};
use anyhow::Result; use anyhow::Result;
use parking_lot::Mutex; use parking_lot::Mutex;
...@@ -241,18 +241,14 @@ where ...@@ -241,18 +241,14 @@ where
} else { } else {
let i = work_queue_stack.len(); let i = work_queue_stack.len();
work_queue_stack.push(Step::TemporarySlot); work_queue_stack.push(Step::TemporarySlot);
let mut has_early_children = false; let has_early_children = val.take_early_children(&mut |child| {
val.for_each_early_children_mut(&mut |child| { work_queue_stack.push(Step::Enter(child));
has_early_children = true;
work_queue_stack.push(Step::Enter(take(child)));
false
}); });
if has_early_children { if has_early_children {
work_queue_stack[i] = Step::EarlyVisit(val); work_queue_stack[i] = Step::EarlyVisit(val);
} else { } else {
val.for_each_children_mut(&mut |child| { val.take_children(&mut |child| {
work_queue_stack.push(Step::Enter(take(child))); work_queue_stack.push(Step::Enter(child));
false
}); });
work_queue_stack[i] = Step::Leave(val); work_queue_stack[i] = Step::Leave(val);
} }
...@@ -263,11 +259,7 @@ where ...@@ -263,11 +259,7 @@ where
// - visit the value // - visit the value
// - insert late children and process for Leave // - insert late children and process for Leave
Step::EarlyVisit(mut val) => { Step::EarlyVisit(mut val) => {
val.for_each_early_children_mut(&mut |child| { val.put_early_children_from_done(&mut done);
let val = done.pop().unwrap();
*child = val;
true
});
val.debug_assert_total_nodes_up_to_date(); val.debug_assert_total_nodes_up_to_date();
let count = val.total_nodes(); let count = val.total_nodes();
total_nodes -= count; total_nodes -= count;
...@@ -305,20 +297,15 @@ where ...@@ -305,20 +297,15 @@ where
// Otherwise we can just process the late children // Otherwise we can just process the late children
let i = work_queue_stack.len(); let i = work_queue_stack.len();
work_queue_stack.push(Step::TemporarySlot); work_queue_stack.push(Step::TemporarySlot);
val.for_each_late_children_mut(&mut |child| { val.take_late_children(&mut |child| {
work_queue_stack.push(Step::Enter(take(child))); work_queue_stack.push(Step::Enter(child));
false
}); });
work_queue_stack[i] = Step::LeaveLate(val); work_queue_stack[i] = Step::LeaveLate(val);
} }
} }
// Leave a value // Leave a value
Step::Leave(mut val) => { Step::Leave(mut val) => {
val.for_each_children_mut(&mut |child| { val.put_children_from_done(&mut done);
let val = done.pop().unwrap();
*child = val;
true
});
val.debug_assert_total_nodes_up_to_date(); val.debug_assert_total_nodes_up_to_date();
let count = val.total_nodes(); let count = val.total_nodes();
...@@ -338,11 +325,7 @@ where ...@@ -338,11 +325,7 @@ where
} }
// Leave a value from EarlyVisit // Leave a value from EarlyVisit
Step::LeaveLate(mut val) => { Step::LeaveLate(mut val) => {
val.for_each_late_children_mut(&mut |child| { val.put_late_children_from_done(&mut done);
let val = done.pop().unwrap();
*child = val;
true
});
val.debug_assert_total_nodes_up_to_date(); val.debug_assert_total_nodes_up_to_date();
let count = val.total_nodes(); let count = val.total_nodes();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment