Skip to content

Commit

Permalink
chore: Add logging and reduce number of comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Jul 27, 2024
1 parent 82d24d8 commit 22649eb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions merge/src/merge_terminals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub fn merge_terminals<'a>(
left: &'a Terminal<'a>,
right: &'a Terminal<'a>,
) -> Result<MergedCSTNode<'a>, MergeError> {
log::trace!("Calling merge terminal");

// Nodes of different kind, early return
if left.kind != right.kind {
return Err(MergeError::NodesWithDifferentKinds(
Expand All @@ -15,11 +17,16 @@ pub fn merge_terminals<'a>(
));
}

let left_equals_base = left.value == base.value;
let right_equals_base = right.value == base.value;

// Unchanged
if left.value == base.value && right.value == base.value {
if left_equals_base && right_equals_base {
log::trace!("Unchanged");
Ok(base.into())
// Changed in both
} else if left.value != base.value && right.value != base.value {
} else if !left_equals_base && !right_equals_base {
log::trace!("Changed in both");
match diffy::merge(base.value, left.value, right.value) {
Ok(value) => Ok(MergedCSTNode::Terminal {
kind: base.kind,
Expand All @@ -31,10 +38,12 @@ pub fn merge_terminals<'a>(
}),
}
// Only left changed
} else if left.value != base.value {
} else if right_equals_base {
log::trace!("Only left changed");
Ok(left.into())
// Only right changed
} else {
log::trace!("Only right changed");
Ok(right.into())
}
}
Expand Down

0 comments on commit 22649eb

Please sign in to comment.