Merge pull request #2778 from Ms2ger/parallel

Remove some mem::transmute calls and reduce some unsafe blocks in parallel.rs.
This commit is contained in:
Patrick Walton 2014-07-07 13:49:35 -07:00
commit 7bf4007880

View file

@ -26,7 +26,7 @@ use servo_util::workqueue::{WorkQueue, WorkUnit, WorkerProxy};
use std::mem;
use std::ptr;
use std::sync::atomics::{AtomicInt, Relaxed, SeqCst};
use style::{Stylist, TNode};
use style::TNode;
#[allow(dead_code)]
fn static_assertion(node: UnsafeLayoutNode) {
@ -215,8 +215,7 @@ impl<'a> ParallelPostorderFlowTraversal for AssignHeightsAndStoreOverflowTravers
fn recalc_style_for_node(unsafe_layout_node: UnsafeLayoutNode,
proxy: &mut WorkerProxy<*mut LayoutContext,UnsafeLayoutNode>) {
unsafe {
let layout_context: &mut LayoutContext = mem::transmute(*proxy.user_data());
let layout_context = unsafe { &mut **proxy.user_data() };
// Get a real layout node.
let node: LayoutNode = layout_node_from_unsafe_layout_node(&unsafe_layout_node);
@ -237,8 +236,10 @@ fn recalc_style_for_node(unsafe_layout_node: UnsafeLayoutNode,
// First, check to see whether we can share a style with someone.
let style_sharing_candidate_cache = layout_context.style_sharing_candidate_cache();
let sharing_result = node.share_style_if_possible(style_sharing_candidate_cache,
parent_opt.clone());
let sharing_result = unsafe {
node.share_style_if_possible(style_sharing_candidate_cache,
parent_opt.clone())
};
// Otherwise, match and cascade selectors.
match sharing_result {
@ -247,14 +248,16 @@ fn recalc_style_for_node(unsafe_layout_node: UnsafeLayoutNode,
if node.is_element() {
// Perform the CSS selector matching.
let stylist: &Stylist = mem::transmute(layout_context.stylist);
let stylist = unsafe { &*layout_context.stylist };
node.match_node(stylist, &mut applicable_declarations, &mut shareable);
}
// Perform the CSS cascade.
unsafe {
node.cascade_node(parent_opt,
&applicable_declarations,
layout_context.applicable_declarations_cache());
}
// Add ourselves to the LRU cache.
if shareable {
@ -299,14 +302,11 @@ fn recalc_style_for_node(unsafe_layout_node: UnsafeLayoutNode,
// If we got here, we're a leaf. Start construction of flows for this node.
construct_flows(unsafe_layout_node, proxy)
}
}
fn construct_flows(mut unsafe_layout_node: UnsafeLayoutNode,
proxy: &mut WorkerProxy<*mut LayoutContext,UnsafeLayoutNode>) {
loop {
let layout_context: &mut LayoutContext = unsafe {
mem::transmute(*proxy.user_data())
};
let layout_context = unsafe { &mut **proxy.user_data() };
// Get a real layout node.
let node: LayoutNode = layout_node_from_unsafe_layout_node(&unsafe_layout_node);
@ -373,9 +373,7 @@ fn construct_flows(mut unsafe_layout_node: UnsafeLayoutNode,
fn assign_widths(unsafe_flow: UnsafeFlow,
proxy: &mut WorkerProxy<*mut LayoutContext,UnsafeFlow>) {
let layout_context: &mut LayoutContext = unsafe {
mem::transmute(*proxy.user_data())
};
let layout_context = unsafe { &mut **proxy.user_data() };
let mut assign_widths_traversal = AssignWidthsTraversal {
layout_context: layout_context,
};
@ -384,9 +382,7 @@ fn assign_widths(unsafe_flow: UnsafeFlow,
fn assign_heights_and_store_overflow(unsafe_flow: UnsafeFlow,
proxy: &mut WorkerProxy<*mut LayoutContext,UnsafeFlow>) {
let layout_context: &mut LayoutContext = unsafe {
mem::transmute(*proxy.user_data())
};
let layout_context = unsafe { &mut **proxy.user_data() };
let mut assign_heights_traversal = AssignHeightsAndStoreOverflowTraversal {
layout_context: layout_context,
};
@ -449,9 +445,7 @@ fn compute_absolute_position(unsafe_flow: UnsafeFlow,
fn build_display_list(mut unsafe_flow: UnsafeFlow,
proxy: &mut WorkerProxy<*mut LayoutContext,UnsafeFlow>) {
let layout_context: &mut LayoutContext = unsafe {
mem::transmute(*proxy.user_data())
};
let layout_context = unsafe { &mut **proxy.user_data() };
loop {
unsafe {
@ -510,9 +504,7 @@ fn build_display_list(mut unsafe_flow: UnsafeFlow,
pub fn recalc_style_for_subtree(root_node: &LayoutNode,
layout_context: &mut LayoutContext,
queue: &mut WorkQueue<*mut LayoutContext,UnsafeLayoutNode>) {
unsafe {
queue.data = mem::transmute(layout_context)
}
queue.data = layout_context as *mut _;
// Enqueue the root node.
queue.push(WorkUnit {
@ -529,9 +521,7 @@ pub fn traverse_flow_tree_preorder(root: &mut FlowRef,
time_profiler_chan: TimeProfilerChan,
layout_context: &mut LayoutContext,
queue: &mut WorkQueue<*mut LayoutContext,UnsafeFlow>) {
unsafe {
queue.data = mem::transmute(layout_context)
}
queue.data = layout_context as *mut _;
profile(time::LayoutParallelWarmupCategory, time_profiler_chan, || {
queue.push(WorkUnit {
@ -549,9 +539,7 @@ pub fn build_display_list_for_subtree(root: &mut FlowRef,
time_profiler_chan: TimeProfilerChan,
layout_context: &mut LayoutContext,
queue: &mut WorkQueue<*mut LayoutContext,UnsafeFlow>) {
unsafe {
queue.data = mem::transmute(layout_context)
}
queue.data = layout_context as *mut _;
profile(time::LayoutParallelWarmupCategory, time_profiler_chan, || {
queue.push(WorkUnit {