diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/PatienceDiffIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/PatienceDiffIndex.java index 310c0d5d3..da21c483b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/PatienceDiffIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/PatienceDiffIndex.java @@ -100,9 +100,6 @@ final class PatienceDiffIndex { // arrays. This permits us to get 3 values per entry, without paying // the penalty for an object header on each entry. - /** Cached hash value for an element as returned by {@link #cmp}. */ - private final int[] hash; - /** * A matched (or partially examined) element from the two sequences. * @@ -160,26 +157,15 @@ final class PatienceDiffIndex { this.pBegin = pIdx; this.pEnd = pCnt; - final int blockCnt = region.getLengthB(); - if (blockCnt < 1) { - table = new int[] {}; - tableMask = 0; - - hash = new int[] {}; - ptrs = new long[] {}; - next = new int[] {}; + final int sz = region.getLengthB(); + table = new int[tableSize(sz)]; + tableMask = table.length - 1; - } else { - table = new int[tableSize(blockCnt)]; - tableMask = table.length - 1; - - // As we insert elements we preincrement so that 0 is never a - // valid entry. Therefore we have to allocate one extra space. - // - hash = new int[1 + blockCnt]; - ptrs = new long[hash.length]; - next = new int[hash.length]; - } + // As we insert elements we preincrement so that 0 is never a + // valid entry. Therefore we have to allocate one extra space. + // + ptrs = new long[1 + sz]; + next = new int[ptrs.length]; } /** @@ -201,8 +187,7 @@ final class PatienceDiffIndex { final int end = region.endB; int pIdx = pBegin; SCAN: while (ptr < end) { - final int key = cmp.hash(b, ptr); - final int tIdx = key & tableMask; + final int tIdx = cmp.hash(b, ptr) & tableMask; if (pIdx < pEnd) { final long priorRec = pCommon[pIdx]; @@ -210,7 +195,7 @@ final class PatienceDiffIndex { // We know this region is unique from a prior pass. // Insert the start point, and skip right to the end. // - insertB(key, tIdx, ptr); + insertB(tIdx, ptr); pIdx++; ptr = aOfRaw(priorRec); continue SCAN; @@ -222,9 +207,6 @@ final class PatienceDiffIndex { // was already a different entry present. // for (int eIdx = table[tIdx]; eIdx != 0; eIdx = next[eIdx]) { - if (hash[eIdx] != key) - continue; - final long rec = ptrs[eIdx]; if (cmp.equals(b, ptr, b, bOf(rec))) { ptrs[eIdx] = rec | B_DUPLICATE; @@ -233,14 +215,13 @@ final class PatienceDiffIndex { } } - insertB(key, tIdx, ptr); + insertB(tIdx, ptr); ptr++; } } - private void insertB(final int key, final int tIdx, int ptr) { + private void insertB(final int tIdx, int ptr) { final int eIdx = ++entryCnt; - hash[eIdx] = key; ptrs[eIdx] = ((long) ptr) << B_SHIFT; next[eIdx] = table[tIdx]; table[tIdx] = eIdx; @@ -263,13 +244,13 @@ final class PatienceDiffIndex { final int end = region.endA; int pLast = pBegin - 1; SCAN: while (ptr < end) { - final int key = cmp.hash(a, ptr); - final int tIdx = key & tableMask; + final int tIdx = cmp.hash(a, ptr) & tableMask; for (int eIdx = table[tIdx]; eIdx != 0; eIdx = next[eIdx]) { final long rec = ptrs[eIdx]; + final int bs = bOf(rec); - if (isDuplicate(rec) || hash[eIdx] != key) + if (isDuplicate(rec) || !cmp.equals(a, ptr, b, bs)) continue; final int aPtr = aOfRaw(rec); @@ -280,12 +261,6 @@ final class PatienceDiffIndex { continue SCAN; } - final int bs = bOf(rec); - if (!cmp.equals(a, ptr, b, bs)) { - ptr++; - continue SCAN; - } - // This element is both common and unique. Link the // two sequences together at this point. //