Skip to content

Commit

Permalink
refactor: write more idiomatic code
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Jul 27, 2024
1 parent a63cbd9 commit 68a04ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 9 additions & 4 deletions matching/src/matchings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ impl<'a> Matchings<'a> {
&'a self,
a_node: &'a CSTNode<'a>,
children: &'a [CSTNode<'a>],
) -> Option<&'a MatchingEntry> {
children
.iter()
.find_map(|left_child| self.get_matching_entry(left_child, a_node))
) -> Option<Matching> {
children.iter().find_map(|child| {
let matching_entry = self.get_matching_entry(child, a_node)?;
Some(Matching {
matching_node: child,
score: matching_entry.score,
is_perfect_match: matching_entry.is_perfect_match,
})
})
}

pub fn get_matching_entry(
Expand Down
6 changes: 4 additions & 2 deletions merge/src/unordered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ pub fn unordered_merge<'a>(
}

let matching_base_left = base_left_matchings.find_matching_for(left_child);
let matching_left_right = left_right_matchings.find_matching_for(left_child);
let matching_left_right =
left_right_matchings.find_matching_node_in_children(left_child, right.get_children());

match (matching_base_left, matching_left_right) {
// Added only by left
Expand Down Expand Up @@ -91,7 +92,8 @@ pub fn unordered_merge<'a>(
.filter(|node| !processed_nodes.contains(&node.id()))
{
let matching_base_right = base_right_matchings.find_matching_for(right_child);
let matching_left_right = left_right_matchings.find_matching_for(right_child);
let matching_left_right =
left_right_matchings.find_matching_node_in_children(right_child, left.get_children());

match (matching_base_right, matching_left_right) {
// Added only by right
Expand Down

0 comments on commit 68a04ec

Please sign in to comment.