summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2014-04-18 09:05:05 -0700
committerShawn Pearce <spearce@spearce.org>2014-04-18 10:11:00 -0700
commitcbc7c5c03fa85380b809cbd1bead82f4685d98ca (patch)
treef40f034be96670e271c6f9cbe43bb00c503c6a6d
parent6de12836d72fe4cba9afc297c8988c6fff851fa9 (diff)
downloadjgit-cbc7c5c03fa85380b809cbd1bead82f4685d98ca.tar.gz
jgit-cbc7c5c03fa85380b809cbd1bead82f4685d98ca.zip
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
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffAlgorithm.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiff.java5
2 files changed, 7 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffAlgorithm.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffAlgorithm.java
index 7545821d11..39421c6dee 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffAlgorithm.java
+++ b/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);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiff.java
index 026e63fce5..0979db1e78 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiff.java
+++ b/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: