Cleanup treewalker

This commit is contained in:
Manish Goregaokar 2015-08-15 05:04:23 +05:30
parent b21df4844c
commit 53e155e8ac

View file

@ -104,12 +104,9 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker {
node = n; node = n;
// "2. If node is not null and filtering node returns FILTER_ACCEPT, // "2. If node is not null and filtering node returns FILTER_ACCEPT,
// then set the currentNode attribute to node, return node." // then set the currentNode attribute to node, return node."
match try!(self.accept_node(node.r())) { if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) {
NodeFilterConstants::FILTER_ACCEPT => { self.current_node.set(JS::from_rooted(&node));
self.current_node.set(JS::from_rooted(&node)); return Ok(Some(node))
return Ok(Some(node))
},
_ => {}
} }
}, },
None => break, None => break,
@ -195,12 +192,9 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker {
} }
// "5. Filter node and if the return value is FILTER_ACCEPT, then // "5. Filter node and if the return value is FILTER_ACCEPT, then
// set the currentNode attribute to node and return node." // set the currentNode attribute to node and return node."
match try!(self.accept_node(node.r())) { if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) {
NodeFilterConstants::FILTER_ACCEPT => { self.current_node.set(JS::from_rooted(&node));
self.current_node.set(JS::from_rooted(&node)); return Ok(Some(node))
return Ok(Some(node))
},
_ => {}
} }
} }
// "6. Return null." // "6. Return null."
@ -217,9 +211,8 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker {
loop { loop {
// "1. While result is not FILTER_REJECT and node has a child, run these subsubsteps:" // "1. While result is not FILTER_REJECT and node has a child, run these subsubsteps:"
loop { loop {
match result { if let NodeFilterConstants::FILTER_REJECT = result {
NodeFilterConstants::FILTER_REJECT => break, break;
_ => {}
} }
match node.r().GetFirstChild() { match node.r().GetFirstChild() {
None => break, None => break,
@ -230,12 +223,9 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker {
result = try!(self.accept_node(node.r())); result = try!(self.accept_node(node.r()));
// "3. If result is FILTER_ACCEPT, then // "3. If result is FILTER_ACCEPT, then
// set the currentNode attribute to node and return node." // set the currentNode attribute to node and return node."
match result { if let NodeFilterConstants::FILTER_ACCEPT = result {
NodeFilterConstants::FILTER_ACCEPT => { self.current_node.set(JS::from_rooted(&node));
self.current_node.set(JS::from_rooted(&node)); return Ok(Some(node))
return Ok(Some(node))
},
_ => {}
} }
} }
} }
@ -251,12 +241,9 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker {
result = try!(self.accept_node(node.r())); result = try!(self.accept_node(node.r()));
// "4. If result is FILTER_ACCEPT, then // "4. If result is FILTER_ACCEPT, then
// set the currentNode attribute to node and return node." // set the currentNode attribute to node and return node."
match result { if let NodeFilterConstants::FILTER_ACCEPT = result {
NodeFilterConstants::FILTER_ACCEPT => { self.current_node.set(JS::from_rooted(&node));
self.current_node.set(JS::from_rooted(&node)); return Ok(Some(node))
return Ok(Some(node))
},
_ => {}
} }
} }
} }
@ -391,13 +378,11 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker {
let result = try!(self.accept_node(node.r())); let result = try!(self.accept_node(node.r()));
// "3. If result is FILTER_ACCEPT, then set the currentNode // "3. If result is FILTER_ACCEPT, then set the currentNode
// attribute to node and return node." // attribute to node and return node."
match result { if let NodeFilterConstants::FILTER_ACCEPT = result {
NodeFilterConstants::FILTER_ACCEPT => { self.current_node.set(JS::from_rooted(&node));
self.current_node.set(JS::from_rooted(&node)); return Ok(Some(node))
return Ok(Some(node))
},
_ => {}
} }
// "4. Set sibling to node's first child if type is next, // "4. Set sibling to node's first child if type is next,
// and node's last child if type is previous." // and node's last child if type is previous."
sibling_op = next_child(node.r()); sibling_op = next_child(node.r());
@ -418,9 +403,8 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker {
// "5. Filter node and if the return value is FILTER_ACCEPT, then return null." // "5. Filter node and if the return value is FILTER_ACCEPT, then return null."
Some(n) => { Some(n) => {
node = n; node = n;
match try!(self.accept_node(node.r())) { if let NodeFilterConstants::FILTER_ACCEPT = try!(self.accept_node(node.r())) {
NodeFilterConstants::FILTER_ACCEPT => return Ok(None), return Ok(None)
_ => {}
} }
} }
} }