From a0fd06e5c2696cc6bed396fd513ec8e4465e399c Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 30 Jun 2010 18:50:50 -0700 Subject: [PATCH] Stream whole deflated objects in PackWriter 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 --- .../eclipse/jgit/storage/pack/PackWriter.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java index d39d574814..2fecc68758 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java @@ -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() { -- 2.39.5