From e6e514c89ae93d859415aac04f4fa4192878f853 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 15 Oct 2015 12:37:29 +0200 Subject: [PATCH] Rewrite ParallelPostorderDomTraversal::run_parallel to avoid some unnecessary conversions between LayoutNode and UnsafeLayoutNode. --- components/layout/parallel.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs index ca3415e34b8..358a5e64f5e 100644 --- a/components/layout/parallel.rs +++ b/components/layout/parallel.rs @@ -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) { + // 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; } } }