summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackReverseIndexTest.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackReverseIndex.java15
4 files changed, 18 insertions, 6 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackReverseIndexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackReverseIndexTest.java
index 292e3e758a..cd37c354a5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackReverseIndexTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackReverseIndexTest.java
@@ -37,9 +37,8 @@ public class PackReverseIndexTest extends RepositoryTestCase {
public void setUp() throws Exception {
super.setUp();
// index with both small (< 2^31) and big offsets
- idx = PackIndex.open(JGitTestUtil.getTestResourceFile(
- "pack-huge.idx"));
- reverseIdx = new PackReverseIndex(idx);
+ idx = PackIndex.open(JGitTestUtil.getTestResourceFile("pack-huge.idx"));
+ reverseIdx = PackReverseIndex.computeFromIndex(idx);
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
index c745b8e6ee..466d5d435b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
@@ -1068,7 +1068,7 @@ public final class DfsPackFile extends BlockBasedFile {
DfsReader ctx, DfsStreamKey revKey, PackIndex idx) {
ctx.stats.readReverseIdx++;
long start = System.nanoTime();
- PackReverseIndex revidx = new PackReverseIndex(idx);
+ PackReverseIndex revidx = PackReverseIndex.computeFromIndex(idx);
reverseIndex = revidx;
ctx.stats.readReverseIdxMicros += elapsedMicros(start);
return new DfsBlockCache.Ref<>(
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
index 6e74136c1b..5d401f4518 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
@@ -1148,7 +1148,7 @@ public class Pack implements Iterable<PackIndex.MutableEntry> {
private synchronized PackReverseIndex getReverseIdx() throws IOException {
if (reverseIdx == null)
- reverseIdx = new PackReverseIndex(idx());
+ reverseIdx = PackReverseIndex.computeFromIndex(idx());
return reverseIdx;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackReverseIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackReverseIndex.java
index 1a5adb4a16..fdbd364134 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackReverseIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackReverseIndex.java
@@ -49,13 +49,26 @@ public class PackReverseIndex {
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
* its entries.
*
* @param packIndex
* forward index - entries to (reverse) index.
*/
- public PackReverseIndex(PackIndex packIndex) {
+ private PackReverseIndex(PackIndex packIndex) {
index = packIndex;
final long cnt = index.getObjectCount();