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
/// fetch-and-subtract the parent's children count.
fn run_parallel(&self,
mut unsafe_node: UnsafeLayoutNode,
unsafe_node: UnsafeLayoutNode,
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>) {
// Get a real layout node.
let mut node: LayoutNode = unsafe {
layout_node_from_unsafe_layout_node(&unsafe_node)
};
loop {
// Get a real layout node.
let node: LayoutNode = unsafe {
layout_node_from_unsafe_layout_node(&unsafe_node)
};
// Perform the appropriate operation.
self.process(node);
@ -186,18 +185,18 @@ trait ParallelPostorderDomTraversal : PostorderDomTraversal {
&*parent.borrow_layout_data_unchecked()
};
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
.data
.parallel
.children_count
.fetch_sub(1, Ordering::Relaxed) == 1 {
// We were the last child of our parent. Construct flows for our parent.
} else {
.fetch_sub(1, Ordering::Relaxed) != 1 {
// Get out of here and find another node to work on.
break
}
// We were the last child of our parent. Construct flows for our parent.
node = parent;
}
}
}