aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/parallel.rs
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2017-10-04 19:55:11 -0700
committerMatt Brubeck <mbrubeck@limpet.net>2017-10-04 20:00:31 -0700
commitae67eb5fe3d82356d27fe09f64619aea8e954c09 (patch)
tree041a1c7e9cfbe235da32047b8bde3bec2c547aca /components/layout/parallel.rs
parent3f07cfec7c6e1b0398229cf308b752a060031ac3 (diff)
downloadservo-ae67eb5fe3d82356d27fe09f64619aea8e954c09.tar.gz
servo-ae67eb5fe3d82356d27fe09f64619aea8e954c09.zip
Use raw pointers instead of transmute for UnsafeFlow
Diffstat (limited to 'components/layout/parallel.rs')
-rw-r--r--components/layout/parallel.rs26
1 files changed, 12 insertions, 14 deletions
diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs
index 44b5f83c712..3793ad648a6 100644
--- a/components/layout/parallel.rs
+++ b/components/layout/parallel.rs
@@ -8,6 +8,7 @@
#![allow(unsafe_code)]
+use block::BlockFlow;
use context::LayoutContext;
use flow::{self, Flow};
use flow_ref::FlowRef;
@@ -16,6 +17,7 @@ use rayon;
use servo_config::opts;
use smallvec::SmallVec;
use std::mem;
+use std::ptr;
use std::sync::atomic::{AtomicIsize, Ordering};
use traversal::{AssignBSizes, AssignISizes, BubbleISizes};
use traversal::{PostorderFlowTraversal, PreorderFlowTraversal};
@@ -26,22 +28,18 @@ const CHUNK_SIZE: usize = 16;
pub type FlowList = SmallVec<[UnsafeFlow; CHUNK_SIZE]>;
/// Vtable + pointer representation of a Flow trait object.
-pub type UnsafeFlow = (usize, usize);
+#[derive(Clone, Copy, Eq, PartialEq)]
+pub struct UnsafeFlow(*const Flow);
+
+unsafe impl Sync for UnsafeFlow {}
+unsafe impl Send for UnsafeFlow {}
fn null_unsafe_flow() -> UnsafeFlow {
- (0, 0)
+ UnsafeFlow(ptr::null::<BlockFlow>())
}
pub fn mut_owned_flow_to_unsafe_flow(flow: *mut FlowRef) -> UnsafeFlow {
- unsafe {
- mem::transmute::<&Flow, UnsafeFlow>(&**flow)
- }
-}
-
-pub fn borrowed_flow_to_unsafe_flow(flow: &Flow) -> UnsafeFlow {
- unsafe {
- mem::transmute::<&Flow, UnsafeFlow>(flow)
- }
+ unsafe { UnsafeFlow(&**flow) }
}
/// Information that we need stored in each flow.
@@ -103,7 +101,7 @@ fn bottom_up_flow(mut unsafe_flow: UnsafeFlow,
// of our parent to finish processing? If so, we can continue
// on with our parent; otherwise, we've gotta wait.
let parent: &mut Flow = unsafe {
- mem::transmute(unsafe_parent)
+ &mut *(unsafe_parent.0 as *mut Flow)
};
let parent_base = flow::mut_base(parent);
if parent_base.parallel.children_count.fetch_sub(1, Ordering::Relaxed) == 1 {
@@ -140,7 +138,7 @@ fn top_down_flow<'scope>(unsafe_flows: &[UnsafeFlow],
// Possibly enqueue the children.
for kid in flow::child_iter_mut(flow) {
had_children = true;
- discovered_child_flows.push(borrowed_flow_to_unsafe_flow(kid));
+ discovered_child_flows.push(UnsafeFlow(kid));
}
}
@@ -191,7 +189,7 @@ pub fn reflow(
let assign_isize_traversal = &AssignISizes { layout_context: &context };
let assign_bsize_traversal = &AssignBSizes { layout_context: &context };
- let nodes = [borrowed_flow_to_unsafe_flow(root)];
+ let nodes = [UnsafeFlow(root)];
queue.install(move || {
rayon::scope(move |scope| {