summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasaya Suzuki <masayasuzuki@google.com>2019-06-15 12:07:35 -0700
committerMasaya Suzuki <masayasuzuki@google.com>2019-08-12 10:19:55 -0700
commit566384fa45a9dde5dc463ee90b1593f917eb227c (patch)
tree3e87083293e99ba10ae04dfe009f2ffc2c12a89b
parentdb0eb9f8aef0beed0a8017d455bf016f2aae7647 (diff)
downloadjgit-566384fa45a9dde5dc463ee90b1593f917eb227c.tar.gz
jgit-566384fa45a9dde5dc463ee90b1593f917eb227c.zip
dfs: Move the deeply nested code to its own method
This is a pure code move. Change-Id: I6304d1cb2b22cfce969b7b5eaaec911ea28579c0 Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java173
1 files changed, 89 insertions, 84 deletions
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 be1387ed0c..57d08e425f 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
@@ -195,44 +195,7 @@ public final class DfsPackFile extends BlockBasedFile {
try {
DfsStreamKey idxKey = desc.getStreamKey(INDEX);
DfsBlockCache.Ref<PackIndex> idxref = cache.getOrLoadRef(idxKey,
- () -> {
- try {
- ctx.stats.readIdx++;
- long start = System.nanoTime();
- try (ReadableChannel rc = ctx.db.openFile(desc,
- INDEX)) {
- InputStream in = Channels
- .newInputStream(rc);
- int wantSize = 8192;
- int bs = rc.blockSize();
- if (0 < bs && bs < wantSize) {
- bs = (wantSize / bs) * bs;
- } else if (bs <= 0) {
- bs = wantSize;
- }
- PackIndex idx = PackIndex.read(
- new BufferedInputStream(in, bs));
- int sz = (int) Math.min(
- idx.getObjectCount() * REC_SIZE,
- Integer.MAX_VALUE);
- ctx.stats.readIdxBytes += rc.position();
- index = idx;
- return new DfsBlockCache.Ref<>(idxKey, 0,
- sz, idx);
- } finally {
- ctx.stats.readIdxMicros += elapsedMicros(
- start);
- }
- } catch (EOFException e) {
- throw new IOException(MessageFormat.format(
- DfsText.get().shortReadOfIndex,
- desc.getFileName(INDEX)), e);
- } catch (IOException e) {
- throw new IOException(MessageFormat.format(
- DfsText.get().cannotReadIndex,
- desc.getFileName(INDEX)), e);
- }
- });
+ () -> loadPackIndex(ctx, idxKey));
PackIndex idx = idxref.get();
if (index == null && idx != null) {
index = idx;
@@ -267,44 +230,9 @@ public final class DfsPackFile extends BlockBasedFile {
PackIndex idx = idx(ctx);
PackReverseIndex revidx = getReverseIdx(ctx);
DfsStreamKey bitmapKey = desc.getStreamKey(BITMAP_INDEX);
- DfsBlockCache.Ref<PackBitmapIndex> idxref = cache
- .getOrLoadRef(bitmapKey, () -> {
- ctx.stats.readBitmap++;
- long start = System.nanoTime();
- try (ReadableChannel rc = ctx.db.openFile(desc,
- BITMAP_INDEX)) {
- long size;
- PackBitmapIndex bmidx;
- try {
- InputStream in = Channels.newInputStream(rc);
- int wantSize = 8192;
- int bs = rc.blockSize();
- if (0 < bs && bs < wantSize) {
- bs = (wantSize / bs) * bs;
- } else if (bs <= 0) {
- bs = wantSize;
- }
- in = new BufferedInputStream(in, bs);
- bmidx = PackBitmapIndex.read(in, idx, revidx);
- } finally {
- size = rc.position();
- ctx.stats.readIdxBytes += size;
- ctx.stats.readIdxMicros += elapsedMicros(start);
- }
- int sz = (int) Math.min(size, Integer.MAX_VALUE);
- bitmapIndex = bmidx;
- return new DfsBlockCache.Ref<>(bitmapKey, 0, sz,
- bmidx);
- } catch (EOFException e) {
- throw new IOException(MessageFormat.format(
- DfsText.get().shortReadOfIndex,
- desc.getFileName(BITMAP_INDEX)), e);
- } catch (IOException e) {
- throw new IOException(MessageFormat.format(
- DfsText.get().cannotReadIndex,
- desc.getFileName(BITMAP_INDEX)), e);
- }
- });
+ DfsBlockCache.Ref<PackBitmapIndex> idxref = cache.getOrLoadRef(
+ bitmapKey,
+ () -> loadBitmapIndex(ctx, bitmapKey, idx, revidx));
PackBitmapIndex bmidx = idxref.get();
if (bitmapIndex == null && bmidx != null) {
bitmapIndex = bmidx;
@@ -326,14 +254,8 @@ public final class DfsPackFile extends BlockBasedFile {
PackIndex idx = idx(ctx);
DfsStreamKey revKey = new DfsStreamKey.ForReverseIndex(
desc.getStreamKey(INDEX));
- DfsBlockCache.Ref<PackReverseIndex> revref = cache
- .getOrLoadRef(revKey, () -> {
- 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);
- });
+ DfsBlockCache.Ref<PackReverseIndex> revref = cache.getOrLoadRef(
+ revKey, () -> loadReverseIdx(ctx, revKey, idx));
PackReverseIndex revidx = revref.get();
if (reverseIndex == null && revidx != null) {
reverseIndex = revidx;
@@ -1091,4 +1013,87 @@ public final class DfsPackFile extends BlockBasedFile {
list.add(offset);
}
}
+
+ private DfsBlockCache.Ref<PackIndex> loadPackIndex(
+ DfsReader ctx, DfsStreamKey idxKey) throws IOException {
+ try {
+ ctx.stats.readIdx++;
+ long start = System.nanoTime();
+ try (ReadableChannel rc = ctx.db.openFile(desc, INDEX)) {
+ InputStream in = Channels.newInputStream(rc);
+ int wantSize = 8192;
+ int bs = rc.blockSize();
+ if (0 < bs && bs < wantSize) {
+ bs = (wantSize / bs) * bs;
+ } else if (bs <= 0) {
+ bs = wantSize;
+ }
+ PackIndex idx = PackIndex.read(new BufferedInputStream(in, bs));
+ int sz = (int) Math.min(
+ idx.getObjectCount() * REC_SIZE,
+ Integer.MAX_VALUE);
+ ctx.stats.readIdxBytes += rc.position();
+ index = idx;
+ return new DfsBlockCache.Ref<>(idxKey, 0, sz, idx);
+ } finally {
+ ctx.stats.readIdxMicros += elapsedMicros(start);
+ }
+ } catch (EOFException e) {
+ throw new IOException(MessageFormat.format(
+ DfsText.get().shortReadOfIndex,
+ desc.getFileName(INDEX)), e);
+ } catch (IOException e) {
+ throw new IOException(MessageFormat.format(
+ DfsText.get().cannotReadIndex,
+ desc.getFileName(INDEX)), e);
+ }
+ }
+
+ private DfsBlockCache.Ref<PackReverseIndex> loadReverseIdx(
+ DfsReader ctx, DfsStreamKey revKey, PackIndex idx) {
+ 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);
+ }
+
+ private DfsBlockCache.Ref<PackBitmapIndex> loadBitmapIndex(
+ DfsReader ctx,
+ DfsStreamKey bitmapKey,
+ PackIndex idx,
+ PackReverseIndex revidx) throws IOException {
+ ctx.stats.readBitmap++;
+ long start = System.nanoTime();
+ try (ReadableChannel rc = ctx.db.openFile(desc, BITMAP_INDEX)) {
+ long size;
+ PackBitmapIndex bmidx;
+ try {
+ InputStream in = Channels.newInputStream(rc);
+ int wantSize = 8192;
+ int bs = rc.blockSize();
+ if (0 < bs && bs < wantSize) {
+ bs = (wantSize / bs) * bs;
+ } else if (bs <= 0) {
+ bs = wantSize;
+ }
+ in = new BufferedInputStream(in, bs);
+ bmidx = PackBitmapIndex.read(in, idx, revidx);
+ } finally {
+ size = rc.position();
+ ctx.stats.readIdxBytes += size;
+ ctx.stats.readIdxMicros += elapsedMicros(start);
+ }
+ int sz = (int) Math.min(size, Integer.MAX_VALUE);
+ bitmapIndex = bmidx;
+ return new DfsBlockCache.Ref<>(bitmapKey, 0, sz, bmidx);
+ } catch (EOFException e) {
+ throw new IOException(MessageFormat.format(
+ DfsText.get().shortReadOfIndex,
+ desc.getFileName(BITMAP_INDEX)), e);
+ } catch (IOException e) {
+ throw new IOException(MessageFormat.format(
+ DfsText.get().cannotReadIndex,
+ desc.getFileName(BITMAP_INDEX)), e);
+ }
+ }
}