Browse Source

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 <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
a0fd06e5c2
  1. 20
      org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

20
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.Iterator;
import java.util.List; import java.util.List;
import java.util.zip.Deflater; import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import org.eclipse.jgit.JGitText; import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
@ -752,19 +753,14 @@ public class PackWriter {
private void writeWholeObjectDeflate(PackOutputStream out, private void writeWholeObjectDeflate(PackOutputStream out,
final ObjectToPack otp) throws IOException { final ObjectToPack otp) throws IOException {
final Deflater deflater = deflater(); final Deflater deflater = deflater();
final ObjectLoader loader = reader.open(otp, otp.getType()); final ObjectLoader ldr = reader.open(otp, otp.getType());
final byte[] data = loader.getCachedBytes();
out.writeHeader(otp, data.length); out.writeHeader(otp, ldr.getSize());
deflater.reset(); deflater.reset();
deflater.setInput(data, 0, data.length); DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater);
deflater.finish(); ldr.copyTo(dst);
dst.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());
} }
private Deflater deflater() { private Deflater deflater() {

Loading…
Cancel
Save