aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-09-21 13:53:56 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-09-21 18:00:31 -0700
commite84d826eb6a0649b74d7d374cd6899f4782e51ee (patch)
treedfe450bffde9feda2278c27d3fa4270f886bdb23
parenta67afbfee10ca2963f5f0f52f701376e382572e2 (diff)
downloadjgit-e84d826eb6a0649b74d7d374cd6899f4782e51ee.tar.gz
jgit-e84d826eb6a0649b74d7d374cd6899f4782e51ee.zip
Remove unnecessary hash cache from PatienceDiffIndex
PatienceDiff always uses a HashedSequence, which promises to provide constant time access for hash codes during the equals method and aborts fast if the hash codes don't match. Therefore we don't need to cache the hash codes inside of the index, saving us memory. Change-Id: I80bf1e95094b7670e6c0acc26546364a1012d60e Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/PatienceDiffIndex.java55
1 files changed, 15 insertions, 40 deletions
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 310c0d5d3a..da21c483b5 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<S extends Sequence> {
// 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<S extends Sequence> {
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<S extends Sequence> {
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<S extends Sequence> {
// 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<S extends Sequence> {
// 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<S extends Sequence> {
}
}
- 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<S extends Sequence> {
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<S extends Sequence> {
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.
//