From 38b8c0d741be1cc8f1ddcdc4fdc3a7696c4311d0 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 7 Apr 2008 23:35:55 -0400 Subject: [PATCH] Replace IndexPack writeUInt32 with NB.encodeInt32 Since we already have a common function to write a 32 bit unsigned (or signed) network byte order integer we do not need to create our own in IndexPack. Better to reuse the code we already have. Since rawoe is only used for the ObjectId values within this loop we can instead pack it out an extra 4 spaces and fill the entire index record into one byte array. Signed-off-by: Shawn O. Pearce --- .../src/org/spearce/jgit/fetch/IndexPack.java | 32 ++++++---------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/fetch/IndexPack.java b/org.spearce.jgit/src/org/spearce/jgit/fetch/IndexPack.java index ef1ca5f2..5f3df207 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/fetch/IndexPack.java +++ b/org.spearce.jgit/src/org/spearce/jgit/fetch/IndexPack.java @@ -294,15 +294,17 @@ public class IndexPack { final BufferedOutputStream os = new BufferedOutputStream( new FileOutputStream(dstIdx), BUFFER_SIZE); try { + final byte[] rawoe = new byte[4 + Constants.OBJECT_ID_LENGTH]; final MessageDigest d = Constants.newMessageDigest(); - for (int i = 0; i < 256; i++) - writeUInt32(d, os, fanout[i]); - byte[] rawoe = new byte[Constants.OBJECT_ID_LENGTH]; + for (int i = 0; i < 256; i++) { + NB.encodeInt32(rawoe, 0, fanout[i]); + os.write(rawoe, 0, 4); + d.update(rawoe, 0, 4); + } for (int i = 0; i < entryCount; i++) { final ObjectEntry oe = entries[i]; - writeUInt32(d, os, oe.pos); -// System.out.println(oe + " " + oe.pos); - oe.copyRawTo(rawoe, 0); + NB.encodeInt32(rawoe, 0, (int) oe.pos); + oe.copyRawTo(rawoe, 4); os.write(rawoe); d.update(rawoe); } @@ -562,24 +564,6 @@ public class IndexPack { + dfe.getMessage()); } - private static void writeUInt32(final MessageDigest m, - final BufferedOutputStream o, final long i) throws IOException { - final int a = ((int) (i >> 24)) & 0xff; - final int b = ((int) (i >> 16)) & 0xff; - final int c = ((int) (i >> 8)) & 0xff; - final int d = ((int) i) & 0xff; - - o.write(a); - o.write(b); - o.write(c); - o.write(d); - - m.update((byte) a); - m.update((byte) b); - m.update((byte) c); - m.update((byte) d); - } - private static class ObjectEntry extends ObjectId { final long pos; -- 2.11.4.GIT