Hold a Temporary in ReverseChildrenIterator

This commit is contained in:
Anthony Ramine 2015-04-04 23:04:27 +02:00
parent fc31aef8b4
commit 6a6ecb9afa

View file

@ -862,7 +862,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
fn rev_children(self) -> ReverseChildrenIterator {
ReverseChildrenIterator {
current: self.last_child.get().root(),
current: self.last_child(),
}
}
@ -1132,16 +1132,19 @@ impl Iterator for NodeChildrenIterator {
}
pub struct ReverseChildrenIterator {
current: Option<Root<Node>>,
current: Option<Temporary<Node>>,
}
impl Iterator for ReverseChildrenIterator {
type Item = Temporary<Node>;
fn next(&mut self) -> Option<Temporary<Node>> {
let node = self.current.r().map(Temporary::from_rooted);
self.current = self.current.take().and_then(|node| node.r().prev_sibling()).root();
node
let current = match self.current.take() {
None => return None,
Some(current) => current,
}.root();
self.current = current.r().prev_sibling();
Some(Temporary::from_rooted(current.r()))
}
}