aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2014-08-02 05:35:18 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2014-08-02 05:35:18 -0400
commitfd07ee54efc944e9af29bf31b4af9c0218f47bac (patch)
treeb48f9bade506033acbb1d8100054bf157e3ca03f /org.eclipse.jgit
parent66909cd7a6077298d237b44fd5c116a7c0e814f4 (diff)
parentd11ca1b0845987f1e17c284ea86a264b45bf52d7 (diff)
downloadjgit-fd07ee54efc944e9af29bf31b4af9c0218f47bac.tar.gz
jgit-fd07ee54efc944e9af29bf31b4af9c0218f47bac.zip
Merge "HistogramDiff: Convert stack recursion to heap managed queue"
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiff.java20
1 files changed, 14 insertions, 6 deletions
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 0979db1e78..e57faaf858 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiff.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiff.java
@@ -43,6 +43,9 @@
package org.eclipse.jgit.diff;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* An extended form of Bram Cohen's patience diff algorithm.
* <p>
@@ -130,15 +133,14 @@ public class HistogramDiff extends LowLevelDiffAlgorithm {
public <S extends Sequence> void diffNonCommon(EditList edits,
HashedSequenceComparator<S> cmp, HashedSequence<S> a,
HashedSequence<S> b, Edit region) {
- new State<S>(edits, cmp, a, b).diffReplace(region);
+ new State<S>(edits, cmp, a, b).diffRegion(region);
}
private class State<S extends Sequence> {
private final HashedSequenceComparator<S> cmp;
-
private final HashedSequence<S> a;
-
private final HashedSequence<S> b;
+ private final List<Edit> queue = new ArrayList<Edit>();
/** Result edits we have determined that must be made to convert a to b. */
final EditList edits;
@@ -151,7 +153,13 @@ public class HistogramDiff extends LowLevelDiffAlgorithm {
this.edits = edits;
}
- void diffReplace(Edit r) {
+ void diffRegion(Edit r) {
+ diffReplace(r);
+ while (!queue.isEmpty())
+ diff(queue.remove(queue.size() - 1));
+ }
+
+ private void diffReplace(Edit r) {
Edit lcs = new HistogramDiffIndex<S>(maxChainLength, cmp, a, b, r)
.findLongestCommonSequence();
if (lcs != null) {
@@ -163,8 +171,8 @@ public class HistogramDiff extends LowLevelDiffAlgorithm {
//
edits.add(r);
} else {
- diff(r.before(lcs));
- diff(r.after(lcs));
+ queue.add(r.after(lcs));
+ queue.add(r.before(lcs));
}
} else if (fallback instanceof LowLevelDiffAlgorithm) {