diff options
author | Shawn Pearce <spearce@spearce.org> | 2013-09-04 19:13:55 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2013-09-04 19:13:55 -0400 |
commit | c2a9f9e742f7e6633af130823c154a485e6071b2 (patch) | |
tree | 005bef87ce7fe301401bb6cb43166bc5d3e4f9c5 | |
parent | ff09a3633d464c61ccbe44166595f9db285d8314 (diff) | |
parent | aa8d5ac26c29663ef2792cd2eb1a749746c9307f (diff) | |
download | jgit-c2a9f9e742f7e6633af130823c154a485e6071b2.tar.gz jgit-c2a9f9e742f7e6633af130823c154a485e6071b2.zip |
Merge "Remove unnecessary inflate stride in DfsBlock"
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlock.java | 35 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java | 25 |
2 files changed, 17 insertions, 43 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlock.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlock.java index 1e447b3178..7289b9ee9c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlock.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlock.java @@ -55,17 +55,6 @@ import org.eclipse.jgit.internal.storage.pack.PackOutputStream; /** A cached slice of a {@link DfsPackFile}. */ final class DfsBlock { - /** - * Size in bytes to pass to {@link Inflater} at a time. - * <p> - * Blocks can be large (for example 1 MiB), while compressed objects inside - * of them are very small (for example less than 100 bytes for a delta). JNI - * forces the data supplied to the Inflater to be copied during setInput(), - * so use a smaller stride to reduce the risk that too much unnecessary was - * moved into the native layer. - */ - private static final int INFLATE_STRIDE = 512; - final DfsPackKey pack; final long start; @@ -105,29 +94,9 @@ final class DfsBlock { return n; } - int inflate(Inflater inf, long pos, byte[] dstbuf, int dstoff) - throws DataFormatException { + void setInput(Inflater inf, long pos) { int ptr = (int) (pos - start); - int in = Math.min(INFLATE_STRIDE, block.length - ptr); - if (dstoff < dstbuf.length) - in = Math.min(in, dstbuf.length - dstoff); - inf.setInput(block, ptr, in); - - for (;;) { - int out = inf.inflate(dstbuf, dstoff, dstbuf.length - dstoff); - if (out == 0) { - if (inf.needsInput()) { - ptr += in; - in = Math.min(INFLATE_STRIDE, block.length - ptr); - if (in == 0) - return dstoff; - inf.setInput(block, ptr, in); - continue; - } - return dstoff; - } - dstoff += out; - } + inf.setInput(block, ptr, block.length - ptr); } void crc32(CRC32 out, long pos, int cnt) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java index 26fc035834..d7b222866d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java @@ -616,19 +616,24 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs { boolean headerOnly) throws IOException, DataFormatException { prepareInflater(); pin(pack, position); + block.setInput(inf, position); int dstoff = 0; for (;;) { - dstoff = block.inflate(inf, position, dstbuf, dstoff); - - if (headerOnly && dstoff == dstbuf.length) - return dstoff; - if (inf.needsInput()) { - position += block.remaining(position); - pin(pack, position); - } else if (inf.finished()) - return dstoff; - else + int n = inf.inflate(dstbuf, dstoff, dstbuf.length - dstoff); + if (n == 0) { + if (headerOnly && dstoff == dstbuf.length) + return dstoff; + if (inf.needsInput()) { + position += block.remaining(position); + pin(pack, position); + block.setInput(inf, position); + continue; + } + if (inf.finished()) + return dstoff; throw new DataFormatException(); + } + dstoff += n; } } |