Rewrite ParallelPostorderDomTraversal::run_parallel to avoid some unnecessary conversions between LayoutNode and UnsafeLayoutNode.

This commit is contained in:
Ms2ger 2015-10-15 12:37:29 +02:00
parent 3597c463b5
commit e6e514c89a

View file

@ -165,14 +165,13 @@ trait ParallelPostorderDomTraversal : PostorderDomTraversal {
/// The only communication between siblings is that they both /// The only communication between siblings is that they both
/// fetch-and-subtract the parent's children count. /// fetch-and-subtract the parent's children count.
fn run_parallel(&self, fn run_parallel(&self,
mut unsafe_node: UnsafeLayoutNode, unsafe_node: UnsafeLayoutNode,
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>) { proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>) {
loop {
// Get a real layout node. // Get a real layout node.
let node: LayoutNode = unsafe { let mut node: LayoutNode = unsafe {
layout_node_from_unsafe_layout_node(&unsafe_node) layout_node_from_unsafe_layout_node(&unsafe_node)
}; };
loop {
// Perform the appropriate operation. // Perform the appropriate operation.
self.process(node); self.process(node);
@ -186,18 +185,18 @@ trait ParallelPostorderDomTraversal : PostorderDomTraversal {
&*parent.borrow_layout_data_unchecked() &*parent.borrow_layout_data_unchecked()
}; };
let parent_layout_data = parent_layout_data.as_ref().expect("no layout data"); let parent_layout_data = parent_layout_data.as_ref().expect("no layout data");
unsafe_node = layout_node_to_unsafe_layout_node(&parent);
if parent_layout_data if parent_layout_data
.data .data
.parallel .parallel
.children_count .children_count
.fetch_sub(1, Ordering::Relaxed) == 1 { .fetch_sub(1, Ordering::Relaxed) != 1 {
// We were the last child of our parent. Construct flows for our parent.
} else {
// Get out of here and find another node to work on. // Get out of here and find another node to work on.
break break
} }
// We were the last child of our parent. Construct flows for our parent.
node = parent;
} }
} }
} }