summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasaya Suzuki <masayasuzuki@google.com>2019-06-15 13:10:00 -0700
committerMasaya Suzuki <masayasuzuki@google.com>2019-08-12 10:34:05 -0700
commite837bdd0face058ad4f4f7ebdb4802514719bb94 (patch)
tree172f1b5c61820718c91fc78a76e362f8dc4f3232
parent566384fa45a9dde5dc463ee90b1593f917eb227c (diff)
downloadjgit-e837bdd0face058ad4f4f7ebdb4802514719bb94.tar.gz
jgit-e837bdd0face058ad4f4f7ebdb4802514719bb94.zip
dfs: Add a position argument
This makes DfsBlockCache methods more unified. Also this reduces a magic number embedded in DfsBlockCache. Change-Id: I61e6c93ca283c0395738103bd2d94091edbccd4e Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java11
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java16
2 files changed, 18 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java
index c6e2fae42f..fae302282f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java
@@ -521,17 +521,20 @@ public final class DfsBlockCache {
*
* @param key
* the stream key of the pack.
+ * @param position
+ * the position in the key. The default should be 0.
* @param loader
* the function to load the reference.
* @return the object reference.
* @throws IOException
* the reference was not in the cache and could not be loaded.
*/
- <T> Ref<T> getOrLoadRef(DfsStreamKey key, RefLoader<T> loader)
+ <T> Ref<T> getOrLoadRef(
+ DfsStreamKey key, long position, RefLoader<T> loader)
throws IOException {
- int slot = slot(key, 0);
+ int slot = slot(key, position);
HashEntry e1 = table.get(slot);
- Ref<T> ref = scanRef(e1, key, 0);
+ Ref<T> ref = scanRef(e1, key, position);
if (ref != null) {
getStat(statHit, key).incrementAndGet();
return ref;
@@ -543,7 +546,7 @@ public final class DfsBlockCache {
try {
HashEntry e2 = table.get(slot);
if (e2 != e1) {
- ref = scanRef(e2, key, 0);
+ ref = scanRef(e2, key, position);
if (ref != null) {
getStat(statHit, key).incrementAndGet();
return ref;
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 57d08e425f..bca891a522 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
@@ -89,6 +89,7 @@ import org.eclipse.jgit.util.LongList;
*/
public final class DfsPackFile extends BlockBasedFile {
private static final int REC_SIZE = Constants.OBJECT_ID_LENGTH + 8;
+ private static final long REF_POSITION = 0;
/**
* Lock for initialization of {@link #index} and {@link #corruptObjects}.
@@ -194,7 +195,9 @@ public final class DfsPackFile extends BlockBasedFile {
try {
DfsStreamKey idxKey = desc.getStreamKey(INDEX);
- DfsBlockCache.Ref<PackIndex> idxref = cache.getOrLoadRef(idxKey,
+ DfsBlockCache.Ref<PackIndex> idxref = cache.getOrLoadRef(
+ idxKey,
+ REF_POSITION,
() -> loadPackIndex(ctx, idxKey));
PackIndex idx = idxref.get();
if (index == null && idx != null) {
@@ -232,6 +235,7 @@ public final class DfsPackFile extends BlockBasedFile {
DfsStreamKey bitmapKey = desc.getStreamKey(BITMAP_INDEX);
DfsBlockCache.Ref<PackBitmapIndex> idxref = cache.getOrLoadRef(
bitmapKey,
+ REF_POSITION,
() -> loadBitmapIndex(ctx, bitmapKey, idx, revidx));
PackBitmapIndex bmidx = idxref.get();
if (bitmapIndex == null && bmidx != null) {
@@ -255,7 +259,9 @@ public final class DfsPackFile extends BlockBasedFile {
DfsStreamKey revKey = new DfsStreamKey.ForReverseIndex(
desc.getStreamKey(INDEX));
DfsBlockCache.Ref<PackReverseIndex> revref = cache.getOrLoadRef(
- revKey, () -> loadReverseIdx(ctx, revKey, idx));
+ revKey,
+ REF_POSITION,
+ () -> loadReverseIdx(ctx, revKey, idx));
PackReverseIndex revidx = revref.get();
if (reverseIndex == null && revidx != null) {
reverseIndex = revidx;
@@ -1034,7 +1040,7 @@ public final class DfsPackFile extends BlockBasedFile {
Integer.MAX_VALUE);
ctx.stats.readIdxBytes += rc.position();
index = idx;
- return new DfsBlockCache.Ref<>(idxKey, 0, sz, idx);
+ return new DfsBlockCache.Ref<>(idxKey, REF_POSITION, sz, idx);
} finally {
ctx.stats.readIdxMicros += elapsedMicros(start);
}
@@ -1054,7 +1060,7 @@ public final class DfsPackFile extends BlockBasedFile {
PackReverseIndex revidx = new PackReverseIndex(idx);
int sz = (int) Math.min(idx.getObjectCount() * 8, Integer.MAX_VALUE);
reverseIndex = revidx;
- return new DfsBlockCache.Ref<>(revKey, 0, sz, revidx);
+ return new DfsBlockCache.Ref<>(revKey, REF_POSITION, sz, revidx);
}
private DfsBlockCache.Ref<PackBitmapIndex> loadBitmapIndex(
@@ -1085,7 +1091,7 @@ public final class DfsPackFile extends BlockBasedFile {
}
int sz = (int) Math.min(size, Integer.MAX_VALUE);
bitmapIndex = bmidx;
- return new DfsBlockCache.Ref<>(bitmapKey, 0, sz, bmidx);
+ return new DfsBlockCache.Ref<>(bitmapKey, REF_POSITION, sz, bmidx);
} catch (EOFException e) {
throw new IOException(MessageFormat.format(
DfsText.get().shortReadOfIndex,