From ccd469ce613b95b577b923f7c0a50acfbd35bdf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 17 Aug 2017 09:48:29 +0200 Subject: [PATCH] script: Early return in CompareDocumentPosition to deindent most of the function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emilio Cobos Álvarez --- components/script/dom/node.rs | 94 +++++++++++++++++------------------ 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 7503618884b..8da03a5a701 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -2365,54 +2365,54 @@ impl NodeMethods for Node { fn CompareDocumentPosition(&self, other: &Node) -> u16 { if self == other { // step 2. - 0 - } else { - let mut lastself = Root::from_ref(self); - let mut lastother = Root::from_ref(other); - for ancestor in self.ancestors() { - if &*ancestor == other { - // step 4. - return NodeConstants::DOCUMENT_POSITION_CONTAINS + - NodeConstants::DOCUMENT_POSITION_PRECEDING; - } - lastself = ancestor; - } - for ancestor in other.ancestors() { - if &*ancestor == self { - // step 5. - return NodeConstants::DOCUMENT_POSITION_CONTAINED_BY + - NodeConstants::DOCUMENT_POSITION_FOLLOWING; - } - lastother = ancestor; - } - - if lastself != lastother { - let abstract_uint: uintptr_t = as_uintptr(&self); - let other_uint: uintptr_t = as_uintptr(&*other); - - let random = if abstract_uint < other_uint { - NodeConstants::DOCUMENT_POSITION_FOLLOWING - } else { - NodeConstants::DOCUMENT_POSITION_PRECEDING - }; - // step 3. - return random + - NodeConstants::DOCUMENT_POSITION_DISCONNECTED + - NodeConstants::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC; - } - - for child in lastself.traverse_preorder() { - if &*child == other { - // step 6. - return NodeConstants::DOCUMENT_POSITION_PRECEDING; - } - if &*child == self { - // step 7. - return NodeConstants::DOCUMENT_POSITION_FOLLOWING; - } - } - unreachable!() + return 0 } + + let mut lastself = Root::from_ref(self); + let mut lastother = Root::from_ref(other); + for ancestor in self.ancestors() { + if &*ancestor == other { + // step 4. + return NodeConstants::DOCUMENT_POSITION_CONTAINS + + NodeConstants::DOCUMENT_POSITION_PRECEDING; + } + lastself = ancestor; + } + for ancestor in other.ancestors() { + if &*ancestor == self { + // step 5. + return NodeConstants::DOCUMENT_POSITION_CONTAINED_BY + + NodeConstants::DOCUMENT_POSITION_FOLLOWING; + } + lastother = ancestor; + } + + if lastself != lastother { + let abstract_uint: uintptr_t = as_uintptr(&self); + let other_uint: uintptr_t = as_uintptr(&*other); + + let random = if abstract_uint < other_uint { + NodeConstants::DOCUMENT_POSITION_FOLLOWING + } else { + NodeConstants::DOCUMENT_POSITION_PRECEDING + }; + // step 3. + return random + + NodeConstants::DOCUMENT_POSITION_DISCONNECTED + + NodeConstants::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC; + } + + for child in lastself.traverse_preorder() { + if &*child == other { + // step 6. + return NodeConstants::DOCUMENT_POSITION_PRECEDING; + } + if &*child == self { + // step 7. + return NodeConstants::DOCUMENT_POSITION_FOLLOWING; + } + } + unreachable!() } // https://dom.spec.whatwg.org/#dom-node-contains