merge: optimize 3-way merge case

I haven't done any profiling to see if this is actually useful, but
it's also pretty simple to do.
This commit is contained in:
Martin von Zweigbergk 2023-05-14 22:24:06 -07:00 committed by Martin von Zweigbergk
parent aa2792c5e5
commit ef7b831411

View file

@ -29,6 +29,19 @@ where
"trivial_merge() requires exactly one more adds than removes"
);
// Optimize the common case of a 3-way merge
if adds.len() == 2 {
return if adds[0] == adds[1] {
Some(adds[0].clone())
} else if adds[0] == removes[0] {
Some(adds[1].clone())
} else if adds[1] == removes[0] {
Some(adds[0].clone())
} else {
None
};
}
// Check if all sides made the same change.
// This matches what Git and Mercurial do (in the 3-way case at least), but not
// what Darcs and Pijul do. It means that repeated 3-way merging of multiple