mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Remove most RootedReference uses
We can replace all uses of RootedReference for Option<T> by Option::deref calls.
This commit is contained in:
parent
7bdfad92a5
commit
5fe5e5d6de
34 changed files with 186 additions and 185 deletions
|
@ -230,11 +230,11 @@ impl Node {
|
|||
assert!(new_child.next_sibling.get().is_none());
|
||||
match before {
|
||||
Some(ref before) => {
|
||||
assert!(before.parent_node.get().r() == Some(self));
|
||||
assert!(before.parent_node.get().deref() == Some(self));
|
||||
let prev_sibling = before.GetPreviousSibling();
|
||||
match prev_sibling {
|
||||
None => {
|
||||
assert!(Some(*before) == self.first_child.get().r());
|
||||
assert!(self.first_child.get().deref() == Some(*before));
|
||||
self.first_child.set(Some(new_child));
|
||||
},
|
||||
Some(ref prev_sibling) => {
|
||||
|
@ -276,27 +276,36 @@ impl Node {
|
|||
///
|
||||
/// Fails unless `child` is a child of this node.
|
||||
fn remove_child(&self, child: &Node, cached_index: Option<u32>) {
|
||||
assert!(child.parent_node.get().r() == Some(self));
|
||||
assert!(child.parent_node.get().deref() == Some(self));
|
||||
let prev_sibling = child.GetPreviousSibling();
|
||||
match prev_sibling {
|
||||
None => {
|
||||
self.first_child.set(child.next_sibling.get().r());
|
||||
self.first_child.set(child.next_sibling.get().deref());
|
||||
},
|
||||
Some(ref prev_sibling) => {
|
||||
prev_sibling.next_sibling.set(child.next_sibling.get().r());
|
||||
prev_sibling
|
||||
.next_sibling
|
||||
.set(child.next_sibling.get().deref());
|
||||
},
|
||||
}
|
||||
let next_sibling = child.GetNextSibling();
|
||||
match next_sibling {
|
||||
None => {
|
||||
self.last_child.set(child.prev_sibling.get().r());
|
||||
self.last_child.set(child.prev_sibling.get().deref());
|
||||
},
|
||||
Some(ref next_sibling) => {
|
||||
next_sibling.prev_sibling.set(child.prev_sibling.get().r());
|
||||
next_sibling
|
||||
.prev_sibling
|
||||
.set(child.prev_sibling.get().deref());
|
||||
},
|
||||
}
|
||||
|
||||
let context = UnbindContext::new(self, prev_sibling.r(), next_sibling.r(), cached_index);
|
||||
let context = UnbindContext::new(
|
||||
self,
|
||||
prev_sibling.deref(),
|
||||
next_sibling.deref(),
|
||||
cached_index,
|
||||
);
|
||||
|
||||
child.prev_sibling.set(None);
|
||||
child.next_sibling.set(None);
|
||||
|
@ -678,7 +687,7 @@ impl Node {
|
|||
document != window.Document(),
|
||||
is_body_element,
|
||||
document.quirks_mode(),
|
||||
html_element.r() == self.downcast::<Element>(),
|
||||
html_element.deref() == self.downcast::<Element>(),
|
||||
) {
|
||||
// Step 2 && Step 5
|
||||
(true, _, _, _) | (_, false, QuirksMode::Quirks, true) => Rect::zero(),
|
||||
|
@ -725,7 +734,7 @@ impl Node {
|
|||
};
|
||||
|
||||
// Step 6.
|
||||
Node::pre_insert(&node, &parent, viable_previous_sibling.r())?;
|
||||
Node::pre_insert(&node, &parent, viable_previous_sibling.deref())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -748,7 +757,7 @@ impl Node {
|
|||
let node = self.owner_doc().node_from_nodes_and_strings(nodes)?;
|
||||
|
||||
// Step 5.
|
||||
Node::pre_insert(&node, &parent, viable_next_sibling.r())?;
|
||||
Node::pre_insert(&node, &parent, viable_next_sibling.deref())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -771,7 +780,7 @@ impl Node {
|
|||
parent.ReplaceChild(&node, self)?;
|
||||
} else {
|
||||
// Step 6.
|
||||
Node::pre_insert(&node, &parent, viable_next_sibling.r())?;
|
||||
Node::pre_insert(&node, &parent, viable_next_sibling.deref())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -783,7 +792,7 @@ impl Node {
|
|||
let node = doc.node_from_nodes_and_strings(nodes)?;
|
||||
// Step 2.
|
||||
let first_child = self.first_child.get();
|
||||
Node::pre_insert(&node, self, first_child.r()).map(|_| ())
|
||||
Node::pre_insert(&node, self, first_child.deref()).map(|_| ())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-parentnode-append
|
||||
|
@ -968,7 +977,7 @@ impl Node {
|
|||
None => return Err(Error::IndexSize),
|
||||
Some(node) => node,
|
||||
};
|
||||
self.InsertBefore(tr_node, node.r())?;
|
||||
self.InsertBefore(tr_node, node.deref())?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1667,7 +1676,7 @@ impl Node {
|
|||
let reference_child = match child {
|
||||
Some(child) if child == node => {
|
||||
reference_child_root = node.GetNextSibling();
|
||||
reference_child_root.r()
|
||||
reference_child_root.deref()
|
||||
},
|
||||
_ => child,
|
||||
};
|
||||
|
@ -1697,7 +1706,7 @@ impl Node {
|
|||
) {
|
||||
node.owner_doc().add_script_and_layout_blocker();
|
||||
debug_assert!(&*node.owner_doc() == &*parent.owner_doc());
|
||||
debug_assert!(child.map_or(true, |child| Some(parent) == child.GetParentNode().r()));
|
||||
debug_assert!(child.map_or(true, |child| Some(parent) == child.GetParentNode().deref()));
|
||||
|
||||
// Step 1.
|
||||
let count = if node.is::<DocumentFragment>() {
|
||||
|
@ -1718,8 +1727,8 @@ impl Node {
|
|||
// Step 3.
|
||||
new_nodes.extend(node.children().map(|kid| Dom::from_ref(&*kid)));
|
||||
// Step 4.
|
||||
for kid in new_nodes.r() {
|
||||
Node::remove(*kid, node, SuppressObserver::Suppressed);
|
||||
for kid in &*new_nodes {
|
||||
Node::remove(kid, node, SuppressObserver::Suppressed);
|
||||
}
|
||||
// Step 5.
|
||||
vtable_for(&node).children_changed(&ChildrenMutation::replace_all(new_nodes.r(), &[]));
|
||||
|
@ -1772,7 +1781,7 @@ impl Node {
|
|||
}
|
||||
if let SuppressObserver::Unsuppressed = suppress_observers {
|
||||
vtable_for(&parent).children_changed(&ChildrenMutation::insert(
|
||||
previous_sibling.r(),
|
||||
previous_sibling.deref(),
|
||||
new_nodes,
|
||||
child,
|
||||
));
|
||||
|
@ -1780,7 +1789,7 @@ impl Node {
|
|||
let mutation = Mutation::ChildList {
|
||||
added: Some(new_nodes),
|
||||
removed: None,
|
||||
prev: previous_sibling.r(),
|
||||
prev: previous_sibling.deref(),
|
||||
next: child,
|
||||
};
|
||||
MutationObserver::queue_a_mutation_record(&parent, mutation);
|
||||
|
@ -1810,8 +1819,8 @@ impl Node {
|
|||
&[] as &[&Node]
|
||||
};
|
||||
// Step 4.
|
||||
for child in removed_nodes.r() {
|
||||
Node::remove(*child, parent, SuppressObserver::Suppressed);
|
||||
for child in &*removed_nodes {
|
||||
Node::remove(child, parent, SuppressObserver::Suppressed);
|
||||
}
|
||||
// Step 5.
|
||||
if let Some(node) = node {
|
||||
|
@ -1883,18 +1892,18 @@ impl Node {
|
|||
// Step 12.
|
||||
if let SuppressObserver::Unsuppressed = suppress_observers {
|
||||
vtable_for(&parent).children_changed(&ChildrenMutation::replace(
|
||||
old_previous_sibling.r(),
|
||||
old_previous_sibling.deref(),
|
||||
&Some(&node),
|
||||
&[],
|
||||
old_next_sibling.r(),
|
||||
old_next_sibling.deref(),
|
||||
));
|
||||
|
||||
let removed = [node];
|
||||
let mutation = Mutation::ChildList {
|
||||
added: None,
|
||||
removed: Some(&removed),
|
||||
prev: old_previous_sibling.r(),
|
||||
next: old_next_sibling.r(),
|
||||
prev: old_previous_sibling.deref(),
|
||||
next: old_next_sibling.deref(),
|
||||
};
|
||||
MutationObserver::queue_a_mutation_record(&parent, mutation);
|
||||
}
|
||||
|
@ -2204,7 +2213,7 @@ impl NodeMethods for Node {
|
|||
};
|
||||
|
||||
// Step 3.
|
||||
Node::replace_all(node.r(), self);
|
||||
Node::replace_all(node.deref(), self);
|
||||
},
|
||||
NodeTypeId::CharacterData(..) => {
|
||||
let characterdata = self.downcast::<CharacterData>().unwrap();
|
||||
|
@ -2308,10 +2317,10 @@ impl NodeMethods for Node {
|
|||
// Step 7-8.
|
||||
let child_next_sibling = child.GetNextSibling();
|
||||
let node_next_sibling = node.GetNextSibling();
|
||||
let reference_child = if child_next_sibling.r() == Some(node) {
|
||||
node_next_sibling.r()
|
||||
let reference_child = if child_next_sibling.deref() == Some(node) {
|
||||
node_next_sibling.deref()
|
||||
} else {
|
||||
child_next_sibling.r()
|
||||
child_next_sibling.deref()
|
||||
};
|
||||
|
||||
// Step 9.
|
||||
|
@ -2343,7 +2352,7 @@ impl NodeMethods for Node {
|
|||
|
||||
// Step 14.
|
||||
vtable_for(&self).children_changed(&ChildrenMutation::replace(
|
||||
previous_sibling.r(),
|
||||
previous_sibling.deref(),
|
||||
&removed_child,
|
||||
nodes,
|
||||
reference_child,
|
||||
|
@ -2352,7 +2361,7 @@ impl NodeMethods for Node {
|
|||
let mutation = Mutation::ChildList {
|
||||
added: Some(nodes),
|
||||
removed: removed.as_ref().map(|r| &r[..]),
|
||||
prev: previous_sibling.r(),
|
||||
prev: previous_sibling.deref(),
|
||||
next: reference_child,
|
||||
};
|
||||
MutationObserver::queue_a_mutation_record(&self, mutation);
|
||||
|
@ -3014,7 +3023,7 @@ where
|
|||
if head_node == node {
|
||||
head += 1;
|
||||
}
|
||||
if elem_node == node.r() || head == self.len() {
|
||||
if elem_node == &*node || head == self.len() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue