mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Don't leak aux data
This commit is contained in:
parent
b6fdc4cc2c
commit
517504e4fc
4 changed files with 26 additions and 18 deletions
|
@ -116,9 +116,6 @@ impl<T:send,A> Handle<T,A> {
|
||||||
**Warning:** the reader is responsible for keeping this data live!
|
**Warning:** the reader is responsible for keeping this data live!
|
||||||
")]
|
")]
|
||||||
fn set_aux(p: @A) unsafe {
|
fn set_aux(p: @A) unsafe {
|
||||||
let p2 = p;
|
|
||||||
unsafe::forget(p2); // Bump the reference count.
|
|
||||||
|
|
||||||
(**self).read_aux = ptr::addr_of(*p);
|
(**self).read_aux = ptr::addr_of(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,10 @@ enum Msg {
|
||||||
|
|
||||||
fn LayoutTask(render_task: RenderTask, image_cache_task: ImageCacheTask) -> LayoutTask {
|
fn LayoutTask(render_task: RenderTask, image_cache_task: ImageCacheTask) -> LayoutTask {
|
||||||
do spawn_listener::<Msg>|request| {
|
do spawn_listener::<Msg>|request| {
|
||||||
|
|
||||||
|
// This just keeps our dom aux objects alive
|
||||||
|
let mut layout_data_refs = ~[];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match request.recv() {
|
match request.recv() {
|
||||||
PingMsg(ping_channel) => ping_channel.send(content_task::PongMsg),
|
PingMsg(ping_channel) => ping_channel.send(content_task::PongMsg),
|
||||||
|
@ -41,7 +45,7 @@ fn LayoutTask(render_task: RenderTask, image_cache_task: ImageCacheTask) -> Layo
|
||||||
node.dump();
|
node.dump();
|
||||||
|
|
||||||
do util::time::time(~"layout") {
|
do util::time::time(~"layout") {
|
||||||
node.initialize_style_for_subtree();
|
layout_data_refs += node.initialize_style_for_subtree();
|
||||||
node.recompute_style_for_subtree(styles);
|
node.recompute_style_for_subtree(styles);
|
||||||
|
|
||||||
let this_box = node.construct_boxes();
|
let this_box = node.construct_boxes();
|
||||||
|
|
|
@ -164,7 +164,6 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore(reason = "leaks memory")]
|
|
||||||
fn test_percent_height() {
|
fn test_percent_height() {
|
||||||
let scope = NodeScope();
|
let scope = NodeScope();
|
||||||
|
|
||||||
|
@ -178,7 +177,7 @@ mod test {
|
||||||
scope.add_child(parent, child2);
|
scope.add_child(parent, child2);
|
||||||
scope.add_child(child, g1);
|
scope.add_child(child, g1);
|
||||||
scope.add_child(child, g2);
|
scope.add_child(child, g2);
|
||||||
parent.initialize_style_for_subtree();
|
let _handles = parent.initialize_style_for_subtree();
|
||||||
|
|
||||||
do parent.aux |aux| { aux.specified_style.height = some(Px(100.0)); }
|
do parent.aux |aux| { aux.specified_style.height = some(Px(100.0)); }
|
||||||
do child.aux |aux| { aux.specified_style.height = some(Auto); }
|
do child.aux |aux| { aux.specified_style.height = some(Auto); }
|
||||||
|
|
|
@ -75,7 +75,7 @@ fn empty_style_for_node_kind(kind: NodeKind) -> SpecifiedStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
trait StylePriv {
|
trait StylePriv {
|
||||||
fn initialize_style();
|
fn initialize_style() -> ~[@LayoutData];
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node : StylePriv {
|
impl Node : StylePriv {
|
||||||
|
@ -89,31 +89,39 @@ impl Node : StylePriv {
|
||||||
"]
|
"]
|
||||||
// TODO: we should look into folding this into building the dom,
|
// TODO: we should look into folding this into building the dom,
|
||||||
// instead of doing a linear sweep afterwards.
|
// instead of doing a linear sweep afterwards.
|
||||||
fn initialize_style() {
|
fn initialize_style() -> ~[@LayoutData] {
|
||||||
let node_kind = self.read(|n| copy *n.kind);
|
if !self.has_aux() {
|
||||||
let the_layout_data = @LayoutData({
|
let node_kind = self.read(|n| copy *n.kind);
|
||||||
mut specified_style : ~empty_style_for_node_kind(node_kind),
|
let the_layout_data = @LayoutData({
|
||||||
mut box : none
|
mut specified_style : ~empty_style_for_node_kind(node_kind),
|
||||||
});
|
mut box : none
|
||||||
|
});
|
||||||
|
|
||||||
self.set_aux(the_layout_data);
|
self.set_aux(the_layout_data);
|
||||||
|
|
||||||
|
~[the_layout_data]
|
||||||
|
} else {
|
||||||
|
~[]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait StyleMethods {
|
trait StyleMethods {
|
||||||
fn initialize_style_for_subtree();
|
fn initialize_style_for_subtree() -> ~[@LayoutData];
|
||||||
fn get_specified_style() -> SpecifiedStyle;
|
fn get_specified_style() -> SpecifiedStyle;
|
||||||
fn recompute_style_for_subtree(styles : arc<Stylesheet>);
|
fn recompute_style_for_subtree(styles : arc<Stylesheet>);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node : StyleMethods {
|
impl Node : StyleMethods {
|
||||||
#[doc="Sequentially initialize the nodes' auxilliary data so they can be updated in parallel."]
|
#[doc="Sequentially initialize the nodes' auxilliary data so they can be updated in parallel."]
|
||||||
fn initialize_style_for_subtree() {
|
fn initialize_style_for_subtree() -> ~[@LayoutData] {
|
||||||
self.initialize_style();
|
let mut handles = self.initialize_style();
|
||||||
|
|
||||||
for NTree.each_child(self) |kid| {
|
for NTree.each_child(self) |kid| {
|
||||||
kid.initialize_style_for_subtree();
|
handles += kid.initialize_style_for_subtree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return handles;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc="
|
#[doc="
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue