git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 5/5] Use Deflater directly in PackWriter

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 26, 2009, 01:21 UTC
Message-ID
<1238030515-31768-5-git-send-email-spearce@spearce.org>
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
Previous: Shawn O. PearceNext: Daniel Cheng
Message 5 of 11 in “Remove dead/unused reset method from CountingOutputStream”
  1. 1/5 Remove dead/unused reset method from CountingOutputStreamShawn O. Pearce, Mar 26, 2009
  2. 2/5 Implement CRC32 computation during PackWriterShawn O. Pearce, Mar 26, 2009
  3. 3/5 Test case for pack index CRC32 when written by PackWriterShawn O. Pearce, Mar 26, 2009
  4. 4/5 Write the pack header in one shotShawn O. Pearce, Mar 26, 2009
  5. 5/5 Use Deflater directly in PackWriterShawn O. Pearce, Mar 26, 2009
  6. Daniel ChengMar 26, 2009
  7. Daniel ChengMar 26, 2009
  8. Robin RosenbergMar 27, 2009
  9. Shawn O. PearceMar 27, 2009
  10. Shawn O. PearceMar 27, 2009
  11. Robin RosenbergMar 27, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.