Skip to content

Commit

Permalink
src/matcher.rs: refactor Matches.next
Browse files Browse the repository at this point in the history
  • Loading branch information
niklak committed Jan 1, 2024
1 parent eff9d04 commit fc6ec0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/dom_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ fn children_of<T>(nodes: &Ref<Vec<InnerNode<T>>>, id: &NodeId) -> Vec<NodeId> {
let mut children = vec![];

if let Some(node) = nodes.get(id.value) {
let first_child_id = node.first_child;
let mut next_child_id = first_child_id;
let mut next_child_id = node.first_child;

while let Some(node_id) = next_child_id {
if let Some(node) = nodes.get(node_id.value) {
Expand Down
12 changes: 6 additions & 6 deletions src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ impl<'a> Iterator for Matches<NodeRef<'a, NodeData>> {
let root = self.roots.remove(0);

match self.match_scope {
MatchScope::IncludeNode => self.nodes.insert(0, root),
MatchScope::IncludeNode => self.nodes.push(root),
MatchScope::ChildrenOnly => {
for child in root.children().into_iter().rev() {
self.nodes.insert(0, child);
self.nodes.push(child);
}
}
}
Expand All @@ -119,11 +119,11 @@ impl<'a> Iterator for Matches<NodeRef<'a, NodeData>> {
self.nodes.insert(0, node);
}

if self.matcher.match_element(&node) {
if self.set.contains(&node.id) {
continue;
}
if self.set.contains(&node.id) {
continue;
}

if self.matcher.match_element(&node) {
self.set.insert(node.id);
return Some(node);
}
Expand Down

0 comments on commit fc6ec0c

Please sign in to comment.