Skip to content

Commit

Permalink
Use RefMut::map to simplify iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Sep 25, 2023
1 parent e58de15 commit 18161e6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/tree/taffy_tree/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ impl Default for Taffy {
}
}

/// Iterator over the Vec in a RefMut<'a, (NodeId, Vec<NodeId>)>
/// Iterator over the Vec in a RefMut<'a, Vec<NodeId>>
pub struct RefCellVecIter<'a> {
/// The items to iterate over
children: RefMut<'a, (NodeId, Vec<NodeId>)>,
children: RefMut<'a, Vec<NodeId>>,
/// The next index to return
index: usize,
}
impl<'a> Iterator for RefCellVecIter<'a> {
type Item = NodeId;

fn next(&mut self) -> Option<Self::Item> {
let item = self.children.1.get(self.index).copied();
let item = self.children.get(self.index).copied();
self.index += 1;
item
}
Expand Down Expand Up @@ -104,7 +104,7 @@ impl LayoutTree for Taffy {
find_children_recursive(&mut children, self, node);
*cache = (node, children);
}
RefCellVecIter { children: cache, index: 0 }
RefCellVecIter { children: RefMut::map(cache, |c| &mut c.1), index: 0 }
}

#[inline(always)]
Expand Down

0 comments on commit 18161e6

Please sign in to comment.