aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-03-02 16:45:51 -0700
committerbors-servo <metajack+bors@gmail.com>2015-03-02 16:45:51 -0700
commit65454e51c806c7d91c869a7b4afce872b4eeea57 (patch)
treeea8a871e056521cf1f2cef02474a26979eac1001 /components/script/dom
parent891dd496e3994a96dc76ce247623be6c32a073fb (diff)
parent611fd7a8461a27387c06786d06dd48a39c112393 (diff)
downloadservo-65454e51c806c7d91c869a7b4afce872b4eeea57.tar.gz
servo-65454e51c806c7d91c869a7b4afce872b4eeea57.zip
auto merge of #5086 : glennw/servo/reap-more-stuff, r=jdm
Also introduce a clear() function to layout data which will be used to clear items such as compositor layouts. Clear the layout data when a node becomes display:none.
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/node.rs47
1 files changed, 15 insertions, 32 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 18910764188..a7b5e5484d6 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -177,9 +177,7 @@ impl NodeFlags {
impl Drop for Node {
#[allow(unsafe_blocks)]
fn drop(&mut self) {
- unsafe {
- self.reap_layout_data();
- }
+ self.layout_data.dispose();
}
}
@@ -205,6 +203,8 @@ pub struct LayoutData {
_data: NonZero<*const ()>,
}
+unsafe impl Send for LayoutData {}
+
pub struct LayoutDataRef {
pub data_cell: RefCell<Option<LayoutData>>,
}
@@ -218,18 +218,17 @@ impl LayoutDataRef {
}
}
- /// Returns true if there is layout data present.
- #[inline]
- pub fn is_present(&self) -> bool {
- self.data_cell.borrow().is_some()
- }
-
- /// Take the chan out of the layout data if it is present.
- pub fn take_chan(&self) -> Option<LayoutChan> {
- let mut layout_data = self.data_cell.borrow_mut();
- match &mut *layout_data {
- &mut None => None,
- &mut Some(ref mut layout_data) => Some(layout_data.chan.take().unwrap()),
+ /// Sends layout data, if any, back to the layout task to be destroyed.
+ pub fn dispose(&self) {
+ if let Some(mut layout_data) = mem::replace(&mut *self.borrow_mut(), None) {
+ let layout_chan = layout_data.chan.take();
+ match layout_chan {
+ None => {}
+ Some(chan) => {
+ let LayoutChan(chan) = chan;
+ chan.send(Msg::ReapLayoutData(layout_data)).unwrap()
+ }
+ }
}
}
@@ -258,8 +257,6 @@ impl LayoutDataRef {
}
}
-unsafe impl Send for LayoutDataRef {}
-
/// The different types of nodes.
#[derive(Copy, PartialEq, Debug)]
#[jstraceable]
@@ -302,6 +299,7 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> {
for node in self.traverse_preorder() {
vtable_for(&node).unbind_from_tree(parent_in_doc);
}
+ self.layout_data.dispose();
}
//
@@ -1648,21 +1646,6 @@ impl Node {
Temporary::from_rooted(copy.r())
}
- /// Sends layout data, if any, back to the layout task to be destroyed.
- unsafe fn reap_layout_data(&mut self) {
- if self.layout_data.is_present() {
- let layout_data = mem::replace(&mut self.layout_data, LayoutDataRef::new());
- let layout_chan = layout_data.take_chan();
- match layout_chan {
- None => {}
- Some(chan) => {
- let LayoutChan(chan) = chan;
- chan.send(Msg::ReapLayoutData(layout_data)).unwrap()
- },
- }
- }
- }
-
pub fn collect_text_contents<'a, T: Iterator<Item=JSRef<'a, Node>>>(iterator: T) -> String {
let mut content = String::new();
for node in iterator {