]> source.dussan.org Git - jgit.git/commitdiff
Stream whole deflated objects in PackWriter 24/1024/1
authorShawn O. Pearce <spearce@spearce.org>
Thu, 1 Jul 2010 01:50:50 +0000 (18:50 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Thu, 1 Jul 2010 01:50:50 +0000 (18:50 -0700)
Instead of loading the entire object as a byte array and passing
that into the deflater, let the ObjectLoader copy the object onto
the DeflaterOutputStream.  This has the nice side effect of using
some sort of stride hack in the Sun implementation that may improve
compression performance.

Change-Id: I3f3d681b06af0da93ab96c75468e00e183ff32fe
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

index d39d5748148665a15befbc1eed425bc21824448c..2fecc6875832ab895fcb0e7c9b3f9c7d10dd2b94 100644 (file)
@@ -56,6 +56,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.zip.Deflater;
+import java.util.zip.DeflaterOutputStream;
 
 import org.eclipse.jgit.JGitText;
 import org.eclipse.jgit.errors.CorruptObjectException;
@@ -752,19 +753,14 @@ public class PackWriter {
        private void writeWholeObjectDeflate(PackOutputStream out,
                        final ObjectToPack otp) throws IOException {
                final Deflater deflater = deflater();
-               final ObjectLoader loader = reader.open(otp, otp.getType());
-               final byte[] data = loader.getCachedBytes();
-               out.writeHeader(otp, data.length);
+               final ObjectLoader ldr = reader.open(otp, otp.getType());
+
+               out.writeHeader(otp, ldr.getSize());
+
                deflater.reset();
-               deflater.setInput(data, 0, data.length);
-               deflater.finish();
-
-               byte[] buf = out.getCopyBuffer();
-               do {
-                       final int n = deflater.deflate(buf, 0, buf.length);
-                       if (n > 0)
-                               out.write(buf, 0, n);
-               } while (!deflater.finished());
+               DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater);
+               ldr.copyTo(dst);
+               dst.finish();
        }
 
        private Deflater deflater() {