From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: Marek Zawirski <marek.zawirski@gmail.com>,
Daniel Cheng <j16sdiz+freenet@gmail.com>,
git@vger.kernel.org
Subject: [JGIT PATCH 5/5] Use Deflater directly in PackWriter
Date: Wed, 25 Mar 2009 18:21:55 -0700 [thread overview]
Message-ID: <1238030515-31768-5-git-send-email-spearce@spearce.org> (raw)
In-Reply-To: <1238030515-31768-4-git-send-email-spearce@spearce.org>
Rather than going through all of the indirection that makes up the
DeflaterOutputStream, including the new object construction for it
and the temporary buffer it allocates internally, we can pump data
directly through our Deflater instance and use our existing 16 KB
temporary "buf" for the transient storage as we compress data to
the pack output stream.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/lib/PackWriter.java | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java
index 2f34255..2d05c4e 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java
@@ -47,7 +47,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.zip.Deflater;
-import java.util.zip.DeflaterOutputStream;
import org.spearce.jgit.errors.IncorrectObjectTypeException;
import org.spearce.jgit.errors.MissingObjectException;
@@ -699,12 +698,15 @@ private void writeWholeObject(final ObjectToPack otp) throws IOException {
} else {
final ObjectLoader loader = db.openObject(windowCursor, otp);
final byte[] data = loader.getCachedBytes();
- final DeflaterOutputStream deflaterOut = new DeflaterOutputStream(
- out, deflater);
writeObjectHeader(otp.getType(), data.length);
- deflaterOut.write(data);
- deflaterOut.finish();
deflater.reset();
+ deflater.setInput(data, 0, data.length);
+ deflater.finish();
+ do {
+ final int n = deflater.deflate(buf, 0, buf.length);
+ if (n > 0)
+ out.write(buf, 0, n);
+ } while (!deflater.finished());
}
}
--
1.6.2.1.471.g682837
next prev parent reply other threads:[~2009-03-26 1:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-26 1:21 [JGIT PATCH 1/5] Remove dead/unused reset method from CountingOutputStream Shawn O. Pearce
2009-03-26 1:21 ` [JGIT PATCH 2/5] Implement CRC32 computation during PackWriter Shawn O. Pearce
2009-03-26 1:21 ` [JGIT PATCH 3/5] Test case for pack index CRC32 when written by PackWriter Shawn O. Pearce
2009-03-26 1:21 ` [JGIT PATCH 4/5] Write the pack header in one shot Shawn O. Pearce
2009-03-26 1:21 ` Shawn O. Pearce [this message]
2009-03-26 15:35 ` [JGIT PATCH 3/5] Test case for pack index CRC32 when written by PackWriter Daniel Cheng
2009-03-26 15:35 ` Daniel Cheng
2009-03-27 8:11 ` patch series starting with [JGIT PATCH 1/5] Remove dead/unused reset method from CountingOutputStream Robin Rosenberg
2009-03-27 14:51 ` Shawn O. Pearce
2009-03-27 14:55 ` Shawn O. Pearce
2009-03-27 23:53 ` Robin Rosenberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1238030515-31768-5-git-send-email-spearce@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=j16sdiz+freenet@gmail.com \
--cc=marek.zawirski@gmail.com \
--cc=robin.rosenberg@dewire.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).