]> source.dussan.org Git - jgit.git/commit
Avoid unnecessary second read on OBJ_OFS_DELTA headers 04/704/1
authorShawn O. Pearce <spearce@spearce.org>
Fri, 14 May 2010 21:03:32 +0000 (14:03 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Sat, 15 May 2010 23:09:07 +0000 (16:09 -0700)
commit3cb59216f50f0af652dd0204654f820fed0e36fc
tree114b820d2c5327bf5dfd4310fb30fd2285ec67d5
parent3cba5377dfdad8c36d1f3b0642f56549821b8676
Avoid unnecessary second read on OBJ_OFS_DELTA headers

When we read the object header we copy 20 bytes from the pack data,
then start parsing out the type and the inflated size.  For most
objects, this is only going to require 3 bytes, which is sufficient
to represent objects with inflated sizes of up to 2^16.  The local
buffer however still has 17 bytes remaining in it, and that can be
used to satisfy the OBJ_OFS_DELTA header.

We shouldn't need to worry about walking off the end of the buffer
here, because delta offsets cannot be larger than 64 bits, and that
requires only 9 bytes in the OFS_DELTA encoding.

Assuming worst-case scenarios of 9 bytes for the OFS_DELTA encoding,
the pack file itself must be approaching 2^64 bytes, an infeasible
size to store on any current technology.  However, even if this
were the case we still have 11 bytes for the type/size header.
In that encoding we can represent an object as large as 2^74 bytes,
which is also an infeasible size to process in JGit.

So drop the second read here.

The data offsets we pass into the ObjectLoaders being constructed
need to be computed individually now.  This saves a local variable,
but pushes the addition operation into each branch of the switch.

Change-Id: I6cf64697a9878db87bbf31c7636c03392b47a062
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/lib/PackFile.java