Browse Source

diff: Optimize single line edits

If the header and trailer are identical up to a single line on both
sides, return that REPLACE edit as the only result.  No algorithm can
break down a REPLACE with height of 1.

Change-Id: I483c40e8790cc3e8b322ef6dfce2299491fd0ac7
stable-3.4
Shawn Pearce 11 years ago
parent
commit
cbc7c5c03f
  1. 3
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffAlgorithm.java
  2. 5
      org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiff.java

3
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffAlgorithm.java

@ -114,6 +114,9 @@ public abstract class DiffAlgorithm {
return EditList.singleton(region);
case REPLACE: {
if (region.getLengthA() == 1 && region.getLengthB() == 1)
return EditList.singleton(region);
SubsequenceComparator<S> cs = new SubsequenceComparator<S>(cmp);
Subsequence<S> as = Subsequence.a(a, region);
Subsequence<S> bs = Subsequence.b(b, region);

5
org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiff.java

@ -192,7 +192,10 @@ public class HistogramDiff extends LowLevelDiffAlgorithm {
break;
case REPLACE:
diffReplace(r);
if (r.getLengthA() == 1 && r.getLengthB() == 1)
edits.add(r);
else
diffReplace(r);
break;
case EMPTY:

Loading…
Cancel
Save