]> source.dussan.org Git - jgit.git/commitdiff
Always allocate the PackOutputStream copyBuffer 80/11780/2
authorShawn Pearce <spearce@spearce.org>
Wed, 10 Apr 2013 16:33:56 +0000 (09:33 -0700)
committerShawn Pearce <spearce@spearce.org>
Wed, 10 Apr 2013 19:58:51 +0000 (12:58 -0700)
The getCopyBuffer() is almost always used during output. All known
implementations of ObjectReuseAsIs rely on the buffer to be present,
and the only sane way to get good performance from PackWriter is to
reuse objects during packing.

Avoid a branch and test when obtaining this buffer by making sure
it is always populated.

Change-Id: I200baa0bde5dcdd11bab7787291ad64535c9f7fb

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackOutputStream.java

index ea6781495de2646b4a4712b091ccdb6699cedb3f..fcf054c9cca27f8e2e1b7e7d50f4be0941b94f10 100644 (file)
@@ -67,9 +67,9 @@ public final class PackOutputStream extends OutputStream {
 
        private long count;
 
-       private byte[] headerBuffer = new byte[32];
+       private final byte[] headerBuffer = new byte[32];
 
-       private byte[] copyBuffer;
+       private final byte[] copyBuffer = new byte[16 << 10];
 
        private long checkCancelAt;
 
@@ -216,8 +216,6 @@ public final class PackOutputStream extends OutputStream {
 
        /** @return a temporary buffer writers can use to copy data with. */
        public byte[] getCopyBuffer() {
-               if (copyBuffer == null)
-                       copyBuffer = new byte[16 * 1024];
                return copyBuffer;
        }