]> source.dussan.org Git - jgit.git/commitdiff
Avoid unnecessary decoding of length in PackFile 92/1992/1
authorShawn O. Pearce <spearce@spearce.org>
Wed, 1 Dec 2010 17:59:55 +0000 (09:59 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 1 Dec 2010 17:59:55 +0000 (09:59 -0800)
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 <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java

index 54af0ff8387f28de29af14831a67c0a774ad8af5..8db5c1bd55bbf5d459d7b65145a52a3db8eebb28 100644 (file)
@@ -758,9 +758,6 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
                        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<PackIndex.MutableEntry> {
                                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<PackIndex.MutableEntry> {
                        }
 
                        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;