Skip to content

Commit

Permalink
refactor: move method around
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Jul 27, 2024
1 parent d4007e3 commit a63cbd9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 10 additions & 0 deletions matching/src/matchings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ impl<'a> Matchings<'a> {
})
}

pub fn find_matching_node_in_children(
&'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))
}

pub fn get_matching_entry(
&'a self,
left: &'a CSTNode<'a>,
Expand Down
12 changes: 4 additions & 8 deletions merge/src/ordered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ pub fn ordered_merge<'a>(
while let (Some(cur_left), Some(cur_right)) = (cur_left_option, cur_right_option) {
let matching_base_left = base_left_matchings.find_matching_for(cur_left);
let matching_base_right = base_right_matchings.find_matching_for(cur_right);
let left_matching_in_right = right
.get_children()
.iter()
.find_map(|right_child| left_right_matchings.get_matching_entry(cur_left, right_child));
let right_matching_in_left = left
.get_children()
.iter()
.find_map(|left_child| left_right_matchings.get_matching_entry(left_child, cur_right));
let left_matching_in_right =
left_right_matchings.find_matching_node_in_children(cur_left, right.get_children());
let right_matching_in_left =
left_right_matchings.find_matching_node_in_children(cur_right, left.get_children());
let has_bidirectional_matching_left_right =
left_matching_in_right.is_some() && right_matching_in_left.is_some();

Expand Down

0 comments on commit a63cbd9

Please sign in to comment.