Do not root ChildrenList::node

This commit is contained in:
Anthony Ramine 2015-10-17 15:27:46 +02:00
parent b149e0c979
commit 17cd4202e7

View file

@ -109,7 +109,7 @@ impl ChildrenList {
} }
pub fn len(&self) -> u32 { pub fn len(&self) -> u32 {
self.node.root().children_count() self.node.children_count()
} }
pub fn item(&self, index: u32) -> Option<Root<Node>> { pub fn item(&self, index: u32) -> Option<Root<Node>> {
@ -121,7 +121,7 @@ impl ChildrenList {
} }
if index == 0u32 { if index == 0u32 {
// Item is first child if any, not worth updating last visited. // Item is first child if any, not worth updating last visited.
return self.node.root().GetFirstChild(); return self.node.GetFirstChild();
} }
let last_index = self.last_index.get(); let last_index = self.last_index.get();
if index == last_index { if index == last_index {
@ -137,7 +137,7 @@ impl ChildrenList {
} else if index > last_index { } else if index > last_index {
if index == len - 1u32 { if index == len - 1u32 {
// Item is parent's last child, not worth updating last visited. // Item is parent's last child, not worth updating last visited.
return Some(self.node.root().GetLastChild().unwrap()); return Some(self.node.GetLastChild().unwrap());
} }
if index <= last_index + (len - last_index) / 2u32 { if index <= last_index + (len - last_index) / 2u32 {
// Item is closer to the last visited child and follows it. // Item is closer to the last visited child and follows it.
@ -147,7 +147,7 @@ impl ChildrenList {
} else { } else {
// Item is closer to parent's last child and obviously // Item is closer to parent's last child and obviously
// precedes it. // precedes it.
self.node.root().GetLastChild().unwrap() self.node.GetLastChild().unwrap()
.inclusively_preceding_siblings() .inclusively_preceding_siblings()
.nth((len - index - 1u32) as usize).unwrap() .nth((len - index - 1u32) as usize).unwrap()
} }
@ -159,7 +159,7 @@ impl ChildrenList {
} else { } else {
// Item is closer to parent's first child and obviously follows it. // Item is closer to parent's first child and obviously follows it.
debug_assert!(index < last_index / 2u32); debug_assert!(index < last_index / 2u32);
self.node.root().GetFirstChild().unwrap() self.node.GetFirstChild().unwrap()
.inclusively_following_siblings() .inclusively_following_siblings()
.nth(index as usize) .nth(index as usize)
.unwrap() .unwrap()
@ -263,7 +263,7 @@ impl ChildrenList {
} }
fn reset(&self) { fn reset(&self) {
self.last_visited.set(self.node.root().GetFirstChild().as_ref().map(Root::r)); self.last_visited.set(self.node.GetFirstChild().r());
self.last_index.set(0u32); self.last_index.set(0u32);
} }
} }