Thread (26 messages) flat view 26 messages, 2 authors, 2016-06-15
STALE3735d

[JGIT PATCH 17/23] Only do one getCachedBytes per whole object written

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:45:49
Subsystem: the rest · Maintainer: Linus Torvalds

Getting the size of an object may cause getCachedBytes to be invoked,
and then have its result discarded.  To save time we should make the
call to getCachedBytes first, hold onto the byte[], then obtain the
size off the byte[], and finally write from the byte[].

Signed-off-by: Shawn O. Pearce <redacted>
---
 .../src/org/spearce/jgit/lib/PackWriter.java       |    5 +++--
 1 files changed, 3 insertions(+), 2 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 a0823c7..bb889e8 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java
@@ -710,10 +710,11 @@ private void writeWholeObject(final ObjectToPack otp) throws IOException {
 			otp.disposeLoader();
 		} else {
 			final ObjectLoader loader = db.openObject(windowCursor, otp);
+			final byte[] data = loader.getCachedBytes();
 			final DeflaterOutputStream deflaterOut = new DeflaterOutputStream(
 					out, deflater);
-			writeObjectHeader(otp.getType(), loader.getSize());
-			deflaterOut.write(loader.getCachedBytes());
+			writeObjectHeader(otp.getType(), data.length);
+			deflaterOut.write(data);
 			deflaterOut.finish();
 			deflater.reset();
 		}
-- 
1.6.1.rc4.301.g5497a
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help