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. 3
      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); return EditList.singleton(region);
case REPLACE: { case REPLACE: {
if (region.getLengthA() == 1 && region.getLengthB() == 1)
return EditList.singleton(region);
SubsequenceComparator<S> cs = new SubsequenceComparator<S>(cmp); SubsequenceComparator<S> cs = new SubsequenceComparator<S>(cmp);
Subsequence<S> as = Subsequence.a(a, region); Subsequence<S> as = Subsequence.a(a, region);
Subsequence<S> bs = Subsequence.b(b, region); Subsequence<S> bs = Subsequence.b(b, region);

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

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

Loading…
Cancel
Save