Browse Source

Lazily allocate Deflater in PackWriter

Only allocate the Deflater if we can't reuse everything, but also
make sure we release it when we release the PackWriter's resources.

Change-Id: I16a32b94647af0778658eda87acbafc9a25b314a
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
ad0383734e
  1. 17
      org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

17
org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

@ -182,7 +182,9 @@ public class PackWriter {
// edge objects for thin packs
private final ObjectIdSubclassMap<ObjectId> edgeObjects = new ObjectIdSubclassMap<ObjectId>();
private final Deflater deflater;
private int compressionLevel;
private Deflater myDeflater;
private final ObjectReader reader;
@ -252,7 +254,7 @@ public class PackWriter {
reuseSupport = null;
final CoreConfig coreConfig = configOf(repo).get(CoreConfig.KEY);
deflater = new Deflater(coreConfig.getCompression());
compressionLevel = coreConfig.getCompression();
outputVersion = coreConfig.getPackIndexVersion();
}
@ -639,6 +641,10 @@ public class PackWriter {
/** Release all resources used by this writer. */
public void release() {
reader.release();
if (myDeflater != null) {
myDeflater.end();
myDeflater = null;
}
}
private void searchForReuse(ProgressMonitor compressMonitor)
@ -745,6 +751,7 @@ 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);
@ -760,6 +767,12 @@ public class PackWriter {
} while (!deflater.finished());
}
private Deflater deflater() {
if (myDeflater == null)
myDeflater = new Deflater(compressionLevel);
return myDeflater;
}
private void writeChecksum(PackOutputStream out) throws IOException {
packcsum = out.getDigest();
out.write(packcsum);

Loading…
Cancel
Save