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 <spearce@spearce.org>
This commit is contained in:
parent
d29b5db695
commit
e0a9961b78
|
@ -758,9 +758,6 @@ int getObjectType(final WindowCursor curs, long pos) throws IOException {
|
|||
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 @@ int getObjectType(final WindowCursor curs, long pos) throws IOException {
|
|||
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 @@ int getObjectType(final WindowCursor curs, long pos) throws IOException {
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue