Make Node::style_and_layout_data be a DomRefCell<T>

That way we can use borrow_mut_for_layout and borrow_mut.
This commit is contained in:
Anthony Ramine 2020-04-27 11:09:06 +02:00
parent 15db31769c
commit 518c0660c6
2 changed files with 32 additions and 28 deletions

View file

@ -150,12 +150,9 @@ pub struct Node {
/// are this node. /// are this node.
ranges: WeakRangeVec, ranges: WeakRangeVec,
/// Style+Layout information. Only the layout thread may touch this data. /// Style+Layout information.
/// #[ignore_malloc_size_of = "trait object"]
/// Must be sent back to the layout thread to be destroyed when this style_and_layout_data: DomRefCell<Option<Box<StyleAndOpaqueLayoutData>>>,
/// node is finalized.
#[ignore_malloc_size_of = "Unsafe cell"]
style_and_layout_data: UnsafeCell<Option<Box<StyleAndOpaqueLayoutData>>>,
} }
bitflags! { bitflags! {
@ -1246,13 +1243,11 @@ impl Node {
} }
} }
#[allow(unsafe_code)]
pub fn style(&self) -> Option<Arc<ComputedValues>> { pub fn style(&self) -> Option<Arc<ComputedValues>> {
if !window_from_node(self).layout_reflow(QueryMsg::StyleQuery) { if !window_from_node(self).layout_reflow(QueryMsg::StyleQuery) {
return None; return None;
} }
unsafe { self.style_and_layout_data.borrow().as_ref().map(|data| {
(*self.style_and_layout_data.get()).as_ref().map(|data| {
data.style_data data.style_data
.element_data .element_data
.borrow() .borrow()
@ -1261,7 +1256,6 @@ impl Node {
.clone() .clone()
}) })
} }
}
} }
/// Iterate through `nodes` until we find a `Node` that is not in `not_in` /// Iterate through `nodes` until we find a `Node` that is not in `not_in`
@ -1444,13 +1438,21 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
#[inline] #[inline]
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn get_style_and_opaque_layout_data(self) -> Option<&'dom StyleAndOpaqueLayoutData> { fn get_style_and_opaque_layout_data(self) -> Option<&'dom StyleAndOpaqueLayoutData> {
unsafe { (*self.unsafe_get().style_and_layout_data.get()).as_deref() } unsafe {
self.unsafe_get()
.style_and_layout_data
.borrow_for_layout()
.as_deref()
}
} }
#[inline] #[inline]
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn init_style_and_opaque_layout_data(self, val: Box<StyleAndOpaqueLayoutData>) { unsafe fn init_style_and_opaque_layout_data(self, val: Box<StyleAndOpaqueLayoutData>) {
let data = &mut *self.unsafe_get().style_and_layout_data.get(); let data = self
.unsafe_get()
.style_and_layout_data
.borrow_mut_for_layout();
debug_assert!(data.is_none()); debug_assert!(data.is_none());
*data = Some(val); *data = Some(val);
} }
@ -1458,7 +1460,9 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
#[inline] #[inline]
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn take_style_and_opaque_layout_data(self) -> Box<StyleAndOpaqueLayoutData> { unsafe fn take_style_and_opaque_layout_data(self) -> Box<StyleAndOpaqueLayoutData> {
(*self.unsafe_get().style_and_layout_data.get()) self.unsafe_get()
.style_and_layout_data
.borrow_mut_for_layout()
.take() .take()
.unwrap() .unwrap()
} }
@ -1775,7 +1779,7 @@ impl Node {
inclusive_descendants_version: Cell::new(0), inclusive_descendants_version: Cell::new(0),
ranges: WeakRangeVec::new(), ranges: WeakRangeVec::new(),
style_and_layout_data: UnsafeCell::new(None), style_and_layout_data: Default::default(),
} }
} }

View file

@ -30,10 +30,10 @@ macro_rules! sizeof_checker (
// Update the sizes here // Update the sizes here
sizeof_checker!(size_event_target, EventTarget, 56); sizeof_checker!(size_event_target, EventTarget, 56);
sizeof_checker!(size_node, Node, 184); sizeof_checker!(size_node, Node, 192);
sizeof_checker!(size_element, Element, 360); sizeof_checker!(size_element, Element, 368);
sizeof_checker!(size_htmlelement, HTMLElement, 376); sizeof_checker!(size_htmlelement, HTMLElement, 384);
sizeof_checker!(size_div, HTMLDivElement, 376); sizeof_checker!(size_div, HTMLDivElement, 384);
sizeof_checker!(size_span, HTMLSpanElement, 376); sizeof_checker!(size_span, HTMLSpanElement, 384);
sizeof_checker!(size_text, Text, 216); sizeof_checker!(size_text, Text, 224);
sizeof_checker!(size_characterdata, CharacterData, 216); sizeof_checker!(size_characterdata, CharacterData, 224);