mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
script: Don't create a temporary vector on the heap when inserting
non-fragment nodes.
This commit is contained in:
parent
6a7a96a86c
commit
8ab354ac08
1 changed files with 39 additions and 29 deletions
|
@ -1352,29 +1352,8 @@ impl Node {
|
||||||
parent: JSRef<Node>,
|
parent: JSRef<Node>,
|
||||||
child: Option<JSRef<Node>>,
|
child: Option<JSRef<Node>>,
|
||||||
suppress_observers: SuppressObserver) {
|
suppress_observers: SuppressObserver) {
|
||||||
// XXX assert owner_doc
|
fn do_insert(node: JSRef<Node>, parent: JSRef<Node>, child: Option<JSRef<Node>>) {
|
||||||
// Step 1-3: ranges.
|
parent.add_child(node, child);
|
||||||
// Step 4.
|
|
||||||
let mut nodes = match node.type_id() {
|
|
||||||
DocumentFragmentNodeTypeId => node.children().collect(),
|
|
||||||
_ => vec!(node.clone()),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Step 5: DocumentFragment, mutation records.
|
|
||||||
// Step 6: DocumentFragment.
|
|
||||||
match node.type_id() {
|
|
||||||
DocumentFragmentNodeTypeId => {
|
|
||||||
for c in node.children() {
|
|
||||||
Node::remove(c, node, Suppressed);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 7: mutation records.
|
|
||||||
// Step 8.
|
|
||||||
for node in nodes.iter_mut() {
|
|
||||||
parent.add_child(*node, child);
|
|
||||||
let is_in_doc = parent.is_in_doc();
|
let is_in_doc = parent.is_in_doc();
|
||||||
for kid in node.traverse_preorder() {
|
for kid in node.traverse_preorder() {
|
||||||
let mut flags = kid.flags.get();
|
let mut flags = kid.flags.get();
|
||||||
|
@ -1387,17 +1366,48 @@ impl Node {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 9.
|
fn fire_observer_if_necessary(node: JSRef<Node>, suppress_observers: SuppressObserver) {
|
||||||
match suppress_observers {
|
match suppress_observers {
|
||||||
Unsuppressed => {
|
Unsuppressed => node.node_inserted(),
|
||||||
for node in nodes.iter() {
|
|
||||||
node.node_inserted();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Suppressed => ()
|
Suppressed => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX assert owner_doc
|
||||||
|
// Step 1-3: ranges.
|
||||||
|
|
||||||
|
match node.type_id() {
|
||||||
|
DocumentFragmentNodeTypeId => {
|
||||||
|
// Step 4.
|
||||||
|
// Step 5: DocumentFragment, mutation records.
|
||||||
|
// Step 6: DocumentFragment.
|
||||||
|
for c in node.children() {
|
||||||
|
Node::remove(c, node, Suppressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 7: mutation records.
|
||||||
|
// Step 8.
|
||||||
|
for node in node.children() {
|
||||||
|
do_insert(node, parent, child);
|
||||||
|
}
|
||||||
|
|
||||||
|
for node in node.children() {
|
||||||
|
fire_observer_if_necessary(node, suppress_observers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// Step 4.
|
||||||
|
// Step 5: DocumentFragment, mutation records.
|
||||||
|
// Step 6: DocumentFragment.
|
||||||
|
// Step 7: mutation records.
|
||||||
|
// Step 8.
|
||||||
|
do_insert(node, parent, child);
|
||||||
|
// Step 9.
|
||||||
|
fire_observer_if_necessary(node, suppress_observers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#concept-node-replace-all
|
// http://dom.spec.whatwg.org/#concept-node-replace-all
|
||||||
fn replace_all(node: Option<JSRef<Node>>, parent: JSRef<Node>) {
|
fn replace_all(node: Option<JSRef<Node>>, parent: JSRef<Node>) {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue