diff: do not optimize chunks, that are already bounded by empty line

This commit is contained in:
Aleksey Pivovarov
2016-02-17 11:31:35 +03:00
committed by Aleksey Pivovarov
parent 37bccc2af6
commit 7384fdf517
2 changed files with 13 additions and 4 deletions
@@ -82,6 +82,9 @@ abstract class ChunkOptimizer<T> {
int equalForward = expandForward(myData1, myData2, range1.end1, range1.end2, range1.end1 + count2, range1.end2 + count2);
int equalBackward = expandBackward(myData1, myData2, range2.start1 - count1, range2.start2 - count1, range2.start1, range2.start2);
// nothing to do
if (equalForward == 0 && equalBackward == 0) return;
// merge chunks left [A]B[B] -> [AB]B
if (equalForward == count2) {
myRanges.remove(myRanges.size() - 1);
@@ -226,12 +229,12 @@ abstract class ChunkOptimizer<T> {
List<Line> touchLines = touchSide.select(myData1, myData2);
int touchStart = touchSide.select(range2.start1, range2.start2);
int shiftForward = findNextUnimportantLine(touchLines, touchStart, equalForward, 0);
int shiftBackward = findPrevUnimportantLine(touchLines, touchStart - 1, equalBackward, 0);
int shiftForward = findNextUnimportantLine(touchLines, touchStart, equalForward + 1, 0);
int shiftBackward = findPrevUnimportantLine(touchLines, touchStart - 1, equalBackward + 1, 0);
if (shiftForward == -1 && shiftBackward == -1 && myThreshold != 0) {
shiftForward = findNextUnimportantLine(touchLines, touchStart, equalForward, myThreshold);
shiftBackward = findPrevUnimportantLine(touchLines, touchStart - 1, equalBackward, myThreshold);
shiftForward = findNextUnimportantLine(touchLines, touchStart, equalForward + 1, myThreshold);
shiftBackward = findPrevUnimportantLine(touchLines, touchStart - 1, equalBackward + 1, myThreshold);
}
if (shiftForward == 0 || shiftBackward == 0) return 0;
@@ -269,6 +269,12 @@ class LineComparisonUtilTest : ComparisonUtilTestBase() {
testAll()
}
lines {
("A_B_o_o_Y_Z_ _A_B_ _ _Y_Z" - "A_B_o_o_Y_Z_ _A_B_u_u_Y_Z_ _A_B_ _ _Y_Z")
default(ins(9, 9, 7))
testAll()
}
lines {
("A_B_o_o_ _A_B_z_z" - "A_B_o_o_ _A_B_u_u_ _A_B_z_z")
default(ins(5, 5, 5))