diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2015-08-14 14:34:13 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2015-08-20 16:49:48 +0200 |
commit | 649250130b221685dfa8e570ae07d0d2f634bd40 (patch) | |
tree | 13d4a188e49d12874824f1c7ce98725846baf126 /components/layout/flow.rs | |
parent | 2d22aa8e7e99ef52198e0f5918a2a16483aaba0e (diff) | |
download | servo-649250130b221685dfa8e570ae07d0d2f634bd40.tar.gz servo-649250130b221685dfa8e570ae07d0d2f634bd40.zip |
Replace FlowRef with Arc<Flow>, now that Arc supports DST.
… and WeakFlowRef with Weak<Flow>.
Diffstat (limited to 'components/layout/flow.rs')
-rw-r--r-- | components/layout/flow.rs | 50 |
1 files changed, 10 insertions, 40 deletions
diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 1c559d4e112..e6bf124230b 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -57,7 +57,7 @@ use std::mem; use std::raw; use std::slice::IterMut; use std::sync::Arc; -use std::sync::atomic::{AtomicUsize, Ordering}; +use std::sync::atomic::Ordering; use style::computed_values::{clear, display, empty_cells, float, position, text_align}; use style::properties::{self, ComputedValues}; use style::values::computed::LengthOrPercentageOrAuto; @@ -68,7 +68,7 @@ use util::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; /// /// Note that virtual methods have a cost; we should not overuse them in Servo. Consider adding /// methods to `ImmutableFlowUtils` or `MutableFlowUtils` before adding more methods here. -pub trait Flow: fmt::Debug + Sync { +pub trait Flow: fmt::Debug + Sync + Send + 'static { // RTTI // // TODO(pcwalton): Use Rust's RTTI, once that works. @@ -770,9 +770,9 @@ pub struct AbsoluteDescendantIter<'a> { } impl<'a> Iterator for AbsoluteDescendantIter<'a> { - type Item = &'a mut (Flow + 'a); + type Item = &'a mut Flow; #[allow(unsafe_code)] - fn next(&mut self) -> Option<&'a mut (Flow + 'a)> { + fn next(&mut self) -> Option<&'a mut Flow> { self.iter.next().map(|info| unsafe { flow_ref::deref_mut(&mut info.flow) }) } } @@ -815,13 +815,6 @@ impl AbsolutePositionInfo { /// Data common to all flows. pub struct BaseFlow { - /// NB: Must be the first element. - /// - /// The necessity of this will disappear once we have dynamically-sized types. - strong_ref_count: AtomicUsize, - - weak_ref_count: AtomicUsize, - pub restyle_damage: RestyleDamage, /// The children of this flow. @@ -963,15 +956,6 @@ impl Encodable for BaseFlow { } } -impl Drop for BaseFlow { - fn drop(&mut self) { - if self.strong_ref_count.load(Ordering::SeqCst) != 0 && - self.weak_ref_count.load(Ordering::SeqCst) != 0 { - panic!("Flow destroyed before its ref count hit zero—this is unsafe!") - } - } -} - /// Whether a base flow should be forced to be nonfloated. This can affect e.g. `TableFlow`, which /// is never floated because the table wrapper flow is the floated one. #[derive(Clone, PartialEq)] @@ -1039,8 +1023,6 @@ impl BaseFlow { damage.remove(RECONSTRUCT_FLOW); BaseFlow { - strong_ref_count: AtomicUsize::new(1), - weak_ref_count: AtomicUsize::new(1), restyle_damage: damage, children: FlowList::new(), intrinsic_inline_sizes: IntrinsicISizes::new(), @@ -1069,16 +1051,6 @@ impl BaseFlow { self.children.iter_mut() } - #[allow(unsafe_code)] - pub unsafe fn strong_ref_count<'a>(&'a self) -> &'a AtomicUsize { - &self.strong_ref_count - } - - #[allow(unsafe_code)] - pub unsafe fn weak_ref_count<'a>(&'a self) -> &'a AtomicUsize { - &self.weak_ref_count - } - pub fn debug_id(&self) -> usize { let p = self as *const _; p as usize @@ -1115,7 +1087,7 @@ impl BaseFlow { } } -impl<'a> ImmutableFlowUtils for &'a (Flow + 'a) { +impl<'a> ImmutableFlowUtils for &'a Flow { /// Returns true if this flow is a block flow or subclass thereof. fn is_block_like(self) -> bool { match self.class() { @@ -1213,7 +1185,7 @@ impl<'a> ImmutableFlowUtils for &'a (Flow + 'a) { /// as it's harder to understand. fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> FlowRef { let mut style = node.style().clone(); - let flow = match self.class() { + match self.class() { FlowClass::Table | FlowClass::TableRowGroup => { properties::modify_style_for_anonymous_table_object( &mut style, @@ -1224,7 +1196,7 @@ impl<'a> ImmutableFlowUtils for &'a (Flow + 'a) { style, node.restyle_damage(), SpecificFragmentInfo::TableRow); - box TableRowFlow::from_fragment(fragment) as Box<Flow> + Arc::new(TableRowFlow::from_fragment(fragment)) }, FlowClass::TableRow => { properties::modify_style_for_anonymous_table_object( @@ -1237,14 +1209,12 @@ impl<'a> ImmutableFlowUtils for &'a (Flow + 'a) { node.restyle_damage(), SpecificFragmentInfo::TableCell); let hide = node.style().get_inheritedtable().empty_cells == empty_cells::T::hide; - box TableCellFlow::from_node_fragment_and_visibility_flag(node, fragment, !hide) as - Box<Flow> + Arc::new(TableCellFlow::from_node_fragment_and_visibility_flag(node, fragment, !hide)) }, _ => { panic!("no need to generate a missing child") } - }; - FlowRef::new(flow) + } } /// Returns true if this flow contains fragments that are roots of an absolute flow tree. @@ -1315,7 +1285,7 @@ impl<'a> ImmutableFlowUtils for &'a (Flow + 'a) { } } -impl<'a> MutableFlowUtils for &'a mut (Flow + 'a) { +impl<'a> MutableFlowUtils for &'a mut Flow { /// Traverses the tree in preorder. fn traverse_preorder<T: PreorderFlowTraversal>(self, traversal: &T) { if traversal.should_process(self) { |