diff options
author | Michael Valenta | 2007-11-26 18:40:01 +0000 |
---|---|---|
committer | Michael Valenta | 2007-11-26 18:40:01 +0000 |
commit | 5f23d8ead4e707801bc7a9c90ee69ac492821bd0 (patch) | |
tree | 35bdfaada2a5eb3ffcf16ae7ad96825bf13f8963 | |
parent | f8a668a3c4303a36cb7af8a4c9d807aa0d1e6bfd (diff) | |
download | eclipse.platform.team-5f23d8ead4e707801bc7a9c90ee69ac492821bd0.tar.gz eclipse.platform.team-5f23d8ead4e707801bc7a9c90ee69ac492821bd0.tar.xz eclipse.platform.team-5f23d8ead4e707801bc7a9c90ee69ac492821bd0.zip |
Bug 210688 Three-way compare shows wrong changes
2 files changed, 38 insertions, 46 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java index 6a45d7b87..2a680d397 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java @@ -142,42 +142,39 @@ import org.eclipse.core.runtime.*; * some other collection of lines * @param length The number of non-empty (i.e non-zero) entries in LCS * @param comparator The comparator used to generate the LCS - * - * @return The subsequence lcs compacted and chunks shifted towards the - * front */ - private int[] compactAndShiftLCS(int[] lcsSide, int length, + private void compactAndShiftLCS(int[] lcsSide, int length, IRangeComparator comparator) { - int[] result = new int[length]; - - if (length == 0) { - return result; - } - + // If the LCS is empty, just return + if (length == 0) + return; + // Skip any leading empty slots int j = 0; - while (lcsSide[j] == 0) { j++; } - - result[0] = lcsSide[j]; + // Put the first non-empty value in position 0 + lcsSide[0] = lcsSide[j]; j++; - + // Push all non-empty values down into the first N slots (where N is the length) for (int i = 1; i < length; i++) { while (lcsSide[j] == 0) { j++; } - - int nextLine = result[i - 1] + 1; + // Push the difference down as far as possible by comparing the line at the + // start of the diff with the line and the end and adjusting if they are the same + int nextLine = lcsSide[i - 1] + 1; if (nextLine != lcsSide[j] && comparator.rangesEqual(nextLine - 1, comparator, lcsSide[j] - 1)) { - result[i] = nextLine; + lcsSide[i] = nextLine; } else { - result[i] = lcsSide[j]; + lcsSide[i] = lcsSide[j]; } j++; } - - return result; + // Zero all slots after the length + for (int i = length; i < lcsSide.length; i++) { + lcsSide[i] = 0; + } } /* (non-Javadoc) @@ -185,10 +182,9 @@ import org.eclipse.core.runtime.*; */ public void longestCommonSubsequence(SubMonitor subMonitor) { super.longestCommonSubsequence(subMonitor); - int length = getLength(); if (lcs != null) { // The LCS can be null if one of the sides is empty - lcs[0] = compactAndShiftLCS(lcs[0], length, comparator1); - lcs[1] = compactAndShiftLCS(lcs[1], length, comparator2); + compactAndShiftLCS(lcs[0], getLength(), comparator1); + compactAndShiftLCS(lcs[1], getLength(), comparator2); } } } diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java index 6a45d7b87..2a680d397 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java @@ -142,42 +142,39 @@ import org.eclipse.core.runtime.*; * some other collection of lines * @param length The number of non-empty (i.e non-zero) entries in LCS * @param comparator The comparator used to generate the LCS - * - * @return The subsequence lcs compacted and chunks shifted towards the - * front */ - private int[] compactAndShiftLCS(int[] lcsSide, int length, + private void compactAndShiftLCS(int[] lcsSide, int length, IRangeComparator comparator) { - int[] result = new int[length]; - - if (length == 0) { - return result; - } - + // If the LCS is empty, just return + if (length == 0) + return; + // Skip any leading empty slots int j = 0; - while (lcsSide[j] == 0) { j++; } - - result[0] = lcsSide[j]; + // Put the first non-empty value in position 0 + lcsSide[0] = lcsSide[j]; j++; - + // Push all non-empty values down into the first N slots (where N is the length) for (int i = 1; i < length; i++) { while (lcsSide[j] == 0) { j++; } - - int nextLine = result[i - 1] + 1; + // Push the difference down as far as possible by comparing the line at the + // start of the diff with the line and the end and adjusting if they are the same + int nextLine = lcsSide[i - 1] + 1; if (nextLine != lcsSide[j] && comparator.rangesEqual(nextLine - 1, comparator, lcsSide[j] - 1)) { - result[i] = nextLine; + lcsSide[i] = nextLine; } else { - result[i] = lcsSide[j]; + lcsSide[i] = lcsSide[j]; } j++; } - - return result; + // Zero all slots after the length + for (int i = length; i < lcsSide.length; i++) { + lcsSide[i] = 0; + } } /* (non-Javadoc) @@ -185,10 +182,9 @@ import org.eclipse.core.runtime.*; */ public void longestCommonSubsequence(SubMonitor subMonitor) { super.longestCommonSubsequence(subMonitor); - int length = getLength(); if (lcs != null) { // The LCS can be null if one of the sides is empty - lcs[0] = compactAndShiftLCS(lcs[0], length, comparator1); - lcs[1] = compactAndShiftLCS(lcs[1], length, comparator2); + compactAndShiftLCS(lcs[0], getLength(), comparator1); + compactAndShiftLCS(lcs[1], getLength(), comparator2); } } } |