From e0a9961b781db240d71190dece2fd2c70ea79765 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 1 Dec 2010 09:59:55 -0800 Subject: [PATCH] Avoid unnecessary decoding of length in PackFile If the object type is a whole object and all we want is the type, there is no need to skip the length header. The type is already known and can be returned as-is. Instead skip the length header only for the two delta formats, where the delta base must itself be scanned. Change-Id: I87029258e88924b3e5850bdd6c9006a366191d10 Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/storage/file/PackFile.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java index 54af0ff838..8db5c1bd55 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java @@ -758,9 +758,6 @@ public class PackFile implements Iterable { readFully(pos, ib, 0, 20, curs); int c = ib[0] & 0xff; final int type = (c >> 4) & 7; - int p = 1; - while ((c & 0x80) != 0) - c = ib[p++] & 0xff; switch (type) { case Constants.OBJ_COMMIT: @@ -770,6 +767,9 @@ public class PackFile implements Iterable { return type; case Constants.OBJ_OFS_DELTA: { + int p = 1; + while ((c & 0x80) != 0) + c = ib[p++] & 0xff; c = ib[p++] & 0xff; long ofs = c & 127; while ((c & 128) != 0) { @@ -783,6 +783,9 @@ public class PackFile implements Iterable { } case Constants.OBJ_REF_DELTA: { + int p = 1; + while ((c & 0x80) != 0) + c = ib[p++] & 0xff; readFully(pos + p, ib, 0, 20, curs); pos = findDeltaBase(ObjectId.fromRaw(ib)); continue; -- 2.39.5