[dev-servo] Representing mutation of children lists

2015-07-23 Thread Anthony Ramine
Hello,

I'm currently trying to optimise Node.childList and to do so I need to 
propagate changes in children of nodes to the corresponding NodeList. I took 
upon the task of cleaning the mess that are the various virtual methods called 
on insertion and removal of nodes and introduced a new children_changed() 
virtual method in #6660 [1] and an enum to represent the mutations:

fn children_changed(&self, mutation: &ChildrenMutation);

pub enum ChildrenMutation<'a> {
Append(/* prev */ &'a Node, /* added */ &'a [&'a Node]),
Insert(/* prev */ &'a Node, /* added */ &'a [&'a Node], /* next */ &'a 
Node),
Prepend(/* added */ &'a [&'a Node], /* next */ &'a Node),
Replace(/* prev */ Option<&'a Node>,
/* removed */ &'a Node, /* added */ &'a [&'a Node],
/* next */ Option<&'a Node>),
ReplaceAll(/* removed */ &'a [&'a Node], /* added */ &'a [&'a Node]),
}

Does anyone see an immediate problem with this? This might look bad, but I find 
it quite useful for the actual code in NodeList and it avoids some impossible 
mutations that can be represented by a naive tuple (previous_node, 
removed_nodes, added_nodes, next_node), like removing multiple (but not all) 
children of a node.

Regards.

[1] https://github.com/servo/servo/pull/6660

___
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo


Re: [dev-servo] Representing mutation of children lists

2015-07-24 Thread Anthony Ramine
Le 23 juil. 2015 à 23:50, Anthony Ramine  a écrit :

> 
> 
> [1] https://github.com/servo/servo/pull/6660

For those interested, here is how I plan to use the children_changed() virtual 
method:


https://github.com/nox/servo/commit/3d93cf02fc3df8a02b7fe352e316fa5bcd698b30#diff-2ec3646794cf95948a1fba8af486d9a8R245

This commit optimises NodeList instances obtained through Node.childNodes.

___
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo