diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2020-12-23 02:59:11 +0000 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2021-02-26 16:44:05 +0100 |
commit | 0dc6c32759c9e8284fb6b34ad16ba243d18c7ecb (patch) | |
tree | 62cb60c5db1d523681bbe778f26008f59cee03e1 /components/style/dom.rs | |
parent | f58301ecbc2f61cc6a42a2539f1123ab8bc1db8f (diff) | |
download | servo-0dc6c32759c9e8284fb6b34ad16ba243d18c7ecb.tar.gz servo-0dc6c32759c9e8284fb6b34ad16ba243d18c7ecb.zip |
style: Make next_in_preorder generate slightly better code.
This avoids the panic code in release builds.
Differential Revision: https://phabricator.services.mozilla.com/D100094
Diffstat (limited to 'components/style/dom.rs')
-rw-r--r-- | components/style/dom.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/components/style/dom.rs b/components/style/dom.rs index 2edf5ae7dab..86c5a382891 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -188,22 +188,18 @@ pub trait TNode: Sized + Copy + Clone + Debug + NodeInfo + PartialEq { return Some(c); } - if Some(*self) == scoped_to { - return None; - } - - let mut current = *self; + let mut current = Some(*self); loop { - if let Some(s) = current.next_sibling() { - return Some(s); + if current == scoped_to { + return None; } - let parent = current.parent_node(); - if parent == scoped_to { - return None; + debug_assert!(current.is_some(), "not a descendant of the scope?"); + if let Some(s) = current?.next_sibling() { + return Some(s); } - current = parent.expect("Not a descendant of the scope?"); + current = current?.parent_node(); } } |