PackReverseIndex: use static builder instead of constructor
PackReverseIndex instances are created using the constructor directly, which limits control over the construction logic and refactoring opportunities for the class itself. These will be needed for a file-based implementation of the reverse index. Use a static builder method to create a PackReverseIndex instance using a pack's forward index. Change-Id: I4421d907cd61d9ac932df5377e5e28a81679b63f Signed-off-by: Anna Papitto <annapapitto@google.com>
This commit is contained in:
parent
181b629f7d
commit
74547f4a68
|
@ -37,9 +37,8 @@ public class PackReverseIndexTest extends RepositoryTestCase {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
// index with both small (< 2^31) and big offsets
|
// index with both small (< 2^31) and big offsets
|
||||||
idx = PackIndex.open(JGitTestUtil.getTestResourceFile(
|
idx = PackIndex.open(JGitTestUtil.getTestResourceFile("pack-huge.idx"));
|
||||||
"pack-huge.idx"));
|
reverseIdx = PackReverseIndex.computeFromIndex(idx);
|
||||||
reverseIdx = new PackReverseIndex(idx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1068,7 +1068,7 @@ private DfsBlockCache.Ref<PackReverseIndex> loadReverseIdx(
|
||||||
DfsReader ctx, DfsStreamKey revKey, PackIndex idx) {
|
DfsReader ctx, DfsStreamKey revKey, PackIndex idx) {
|
||||||
ctx.stats.readReverseIdx++;
|
ctx.stats.readReverseIdx++;
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
PackReverseIndex revidx = new PackReverseIndex(idx);
|
PackReverseIndex revidx = PackReverseIndex.computeFromIndex(idx);
|
||||||
reverseIndex = revidx;
|
reverseIndex = revidx;
|
||||||
ctx.stats.readReverseIdxMicros += elapsedMicros(start);
|
ctx.stats.readReverseIdxMicros += elapsedMicros(start);
|
||||||
return new DfsBlockCache.Ref<>(
|
return new DfsBlockCache.Ref<>(
|
||||||
|
|
|
@ -1148,7 +1148,7 @@ synchronized PackBitmapIndex getBitmapIndex() throws IOException {
|
||||||
|
|
||||||
private synchronized PackReverseIndex getReverseIdx() throws IOException {
|
private synchronized PackReverseIndex getReverseIdx() throws IOException {
|
||||||
if (reverseIdx == null)
|
if (reverseIdx == null)
|
||||||
reverseIdx = new PackReverseIndex(idx());
|
reverseIdx = PackReverseIndex.computeFromIndex(idx());
|
||||||
return reverseIdx;
|
return reverseIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,19 @@ public class PackReverseIndex {
|
||||||
/** Mapping from indices in offset order to indices in SHA-1 order. */
|
/** Mapping from indices in offset order to indices in SHA-1 order. */
|
||||||
private final int[] nth;
|
private final int[] nth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute an in-memory pack reverse index from the in-memory pack forward
|
||||||
|
* index. This computation uses insertion sort, which has a quadratic
|
||||||
|
* runtime on average.
|
||||||
|
*
|
||||||
|
* @param packIndex
|
||||||
|
* the forward index to compute from
|
||||||
|
* @return the reverse index instance
|
||||||
|
*/
|
||||||
|
public static PackReverseIndex computeFromIndex(PackIndex packIndex) {
|
||||||
|
return new PackReverseIndex(packIndex);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create reverse index from straight/forward pack index, by indexing all
|
* Create reverse index from straight/forward pack index, by indexing all
|
||||||
* its entries.
|
* its entries.
|
||||||
|
@ -55,7 +68,7 @@ public class PackReverseIndex {
|
||||||
* @param packIndex
|
* @param packIndex
|
||||||
* forward index - entries to (reverse) index.
|
* forward index - entries to (reverse) index.
|
||||||
*/
|
*/
|
||||||
public PackReverseIndex(PackIndex packIndex) {
|
private PackReverseIndex(PackIndex packIndex) {
|
||||||
index = packIndex;
|
index = packIndex;
|
||||||
|
|
||||||
final long cnt = index.getObjectCount();
|
final long cnt = index.getObjectCount();
|
||||||
|
|
Loading…
Reference in New Issue