Skip to content

Commit

Permalink
refactor(merge,model): Use ref instead of box
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Oct 28, 2023
1 parent 67ed3af commit a65591e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
64 changes: 32 additions & 32 deletions merge/src/odered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ pub fn ordered_merge<'a>(
(None, Some(_), Some(_), None, Some(matching_base_right)) => {
if !matching_base_right.is_perfect_match {
result_children.push(CSTNode::Conflict {
left: Box::new(None),
right: Box::new(Some(cur_right.unwrap().to_owned())),
left: None,
right: Some(cur_right.unwrap()),
});
}

Expand All @@ -120,7 +120,7 @@ pub fn ordered_merge<'a>(
}
(None, Some(_), None, None, Some(matching_base_right)) => {
if !matching_base_right.is_perfect_match {
result_children.push(CSTNode::Conflict { left: None.into(), right: Some(cur_right.unwrap().to_owned()).into()})
result_children.push(CSTNode::Conflict { left: None.into(), right: Some(cur_right.unwrap()).into()})
}
cur_right = children_right_it.next();
}
Expand All @@ -131,16 +131,16 @@ pub fn ordered_merge<'a>(
(None, None, Some(matching_base_left), Some(_), Some(_)) => {
if !matching_base_left.is_perfect_match {
result_children.push(CSTNode::Conflict {
left: Box::new(Some(cur_left.unwrap().to_owned())),
right: Box::new(None),
left: Some(cur_left.unwrap()),
right: None,
});
}

cur_left = children_left_it.next();
}
(None, None, Some(matching_base_left), Some(_), None) => {
if !matching_base_left.is_perfect_match {
result_children.push(CSTNode::Conflict { left: Some(cur_left.unwrap().to_owned()).into(), right: None.into() })
result_children.push(CSTNode::Conflict { left: Some(cur_left.unwrap()).into(), right: None.into() })
}
cur_left = children_left_it.next();
}
Expand All @@ -149,20 +149,20 @@ pub fn ordered_merge<'a>(
(true, true) => {}
(true, false) => {
result_children.push(CSTNode::Conflict {
left: Some(cur_left.unwrap().to_owned()).into(),
left: Some(cur_left.unwrap()).into(),
right: None.into()
})
}
(false, true) => {
result_children.push(CSTNode::Conflict {
left: None.into(),
right: Some(cur_right.unwrap().to_owned()).into()
right: Some(cur_right.unwrap()).into()
})
}
(false, false) => {
result_children.push(CSTNode::Conflict {
left: Some(cur_left.unwrap().to_owned()).into(),
right: Some(cur_right.unwrap().to_owned()).into()
left: Some(cur_left.unwrap()).into(),
right: Some(cur_right.unwrap()).into()
})
}
};
Expand All @@ -175,8 +175,8 @@ pub fn ordered_merge<'a>(

if !matching_base_left.is_perfect_match {
result_children.push(CSTNode::Conflict {
left: Box::new(Some(cur_left.unwrap().to_owned())),
right: Box::new(None),
left: Some(cur_left.unwrap()),
right: None,
})
}

Expand All @@ -197,8 +197,8 @@ pub fn ordered_merge<'a>(

if !matching_base_right.is_perfect_match {
result_children.push(CSTNode::Conflict {
left: Box::new(None),
right: Box::new(Some(cur_right.unwrap().to_owned())),
left: None,
right: Some(cur_right.unwrap()),
})
}

Expand All @@ -207,8 +207,8 @@ pub fn ordered_merge<'a>(
}
(None, None, None, None, None) => {
result_children.push(CSTNode::Conflict {
left: Box::new(Some(cur_left.unwrap().to_owned())),
right: Box::new(Some(cur_right.unwrap().to_owned())),
left: Some(cur_left.unwrap()),
right: Some(cur_right.unwrap()),
});

cur_left = children_left_it.next();
Expand Down Expand Up @@ -659,14 +659,14 @@ mod tests {
}],
},
CSTNode::Conflict {
left: Box::new(None),
right: Box::new(Some(CSTNode::NonTerminal {
left: None,
right: Some(&CSTNode::NonTerminal {
kind: "subtree".into(),
children: vec![CSTNode::Terminal {
kind: "kind_c".into(),
value: "value_c".into(),
}],
})),
}),
},
],
},
Expand All @@ -685,14 +685,14 @@ mod tests {
}],
},
CSTNode::Conflict {
left: Box::new(Some(CSTNode::NonTerminal {
left: Some(&CSTNode::NonTerminal {
kind: "subtree".into(),
children: vec![CSTNode::Terminal {
kind: "kind_c".into(),
value: "value_c".into(),
}],
})),
right: Box::new(None),
}),
right: None,
},
],
},
Expand Down Expand Up @@ -730,14 +730,14 @@ mod tests {
&CSTNode::NonTerminal {
kind: "kind".into(),
children: vec![CSTNode::Conflict {
left: Box::new(Some(CSTNode::Terminal {
left: Some(&CSTNode::Terminal {
kind: "kind_a".into(),
value: "value_a".into(),
})),
right: Box::new(Some(CSTNode::Terminal {
}),
right: Some(&CSTNode::Terminal {
kind: "kind_b".into(),
value: "value_b".into(),
})),
}),
}],
},
)
Expand Down Expand Up @@ -847,7 +847,7 @@ mod tests {
kind: "kind".into(),
children: vec![
CSTNode::Conflict {
left: Some(CSTNode::NonTerminal {
left: Some(&CSTNode::NonTerminal {
kind: "subtree".into(),
children: vec![CSTNode::Terminal {
kind: "kind_c".into(),
Expand All @@ -874,7 +874,7 @@ mod tests {
children: vec![
CSTNode::Conflict {
left: None.into(),
right: Some(CSTNode::NonTerminal {
right: Some(&CSTNode::NonTerminal {
kind: "subtree".into(),
children: vec![CSTNode::Terminal {
kind: "kind_c".into(),
Expand Down Expand Up @@ -1061,7 +1061,7 @@ mod tests {
children: vec![
CSTNode::Conflict {
left: None.into(),
right: Some(CSTNode::NonTerminal {
right: Some(&CSTNode::NonTerminal {
kind: "subtree",
children: vec![CSTNode::Terminal {
kind: "kind_b",
Expand All @@ -1085,7 +1085,7 @@ mod tests {
kind: "kind".into(),
children: vec![
CSTNode::Conflict {
left: Some(CSTNode::NonTerminal {
left: Some(&CSTNode::NonTerminal {
kind: "subtree",
children: vec![CSTNode::Terminal {
kind: "kind_b",
Expand Down Expand Up @@ -1252,7 +1252,7 @@ mod tests {
&CSTNode::NonTerminal {
kind: "kind",
children: vec![CSTNode::Conflict {
left: Some(CSTNode::NonTerminal {
left: Some(&CSTNode::NonTerminal {
kind: "subtree_b",
children: vec![CSTNode::Terminal {
kind: "kind_c",
Expand All @@ -1272,7 +1272,7 @@ mod tests {
kind: "kind",
children: vec![CSTNode::Conflict {
left: None.into(),
right: Some(CSTNode::NonTerminal {
right: Some(&CSTNode::NonTerminal {
kind: "subtree_b",
children: vec![CSTNode::Terminal {
kind: "kind_c",
Expand Down
4 changes: 2 additions & 2 deletions model/src/cst_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub enum CSTNode<'a> {
children: Vec<CSTNode<'a>>,
},
Conflict {
left: Box<Option<CSTNode<'a>>>,
right: Box<Option<CSTNode<'a>>>,
left: Option<&'a CSTNode<'a>>,
right: Option<&'a CSTNode<'a>>,
},
}

Expand Down

0 comments on commit a65591e

Please sign in to comment.