PackWriter: Remove dummy list 0
Instead of looping over the objectsLists array, always set slot 0 to null and explicitly work on the 4 indexes that matter. This kills some loops and increases the length of the code slightly, but I've always really disliked that dummy 0 slot. Change-Id: I5ad938501c1c61f637ffdaff0d0d88e3962d8942 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
9f5bbb5dd4
commit
0be24ebf33
|
@ -214,7 +214,6 @@ improperlyPaddedBase64Input=Improperly padded Base64 input.
|
||||||
inMemoryBufferLimitExceeded=In-memory buffer limit exceeded
|
inMemoryBufferLimitExceeded=In-memory buffer limit exceeded
|
||||||
incorrectHashFor=Incorrect hash for {0}; computed {1} as a {2} from {3} bytes.
|
incorrectHashFor=Incorrect hash for {0}; computed {1} as a {2} from {3} bytes.
|
||||||
incorrectOBJECT_ID_LENGTH=Incorrect OBJECT_ID_LENGTH.
|
incorrectOBJECT_ID_LENGTH=Incorrect OBJECT_ID_LENGTH.
|
||||||
incorrectObjectType_COMMITnorTREEnorBLOBnorTAG=COMMIT nor TREE nor BLOB nor TAG
|
|
||||||
indexFileIsInUse=Index file is in use
|
indexFileIsInUse=Index file is in use
|
||||||
indexFileIsTooLargeForJgit=Index file is too large for jgit
|
indexFileIsTooLargeForJgit=Index file is too large for jgit
|
||||||
indexSignatureIsInvalid=Index signature is invalid: {0}
|
indexSignatureIsInvalid=Index signature is invalid: {0}
|
||||||
|
|
|
@ -274,7 +274,6 @@ public static JGitText get() {
|
||||||
/***/ public String inMemoryBufferLimitExceeded;
|
/***/ public String inMemoryBufferLimitExceeded;
|
||||||
/***/ public String incorrectHashFor;
|
/***/ public String incorrectHashFor;
|
||||||
/***/ public String incorrectOBJECT_ID_LENGTH;
|
/***/ public String incorrectOBJECT_ID_LENGTH;
|
||||||
/***/ public String incorrectObjectType_COMMITnorTREEnorBLOBnorTAG;
|
|
||||||
/***/ public String indexFileIsInUse;
|
/***/ public String indexFileIsInUse;
|
||||||
/***/ public String indexFileIsTooLargeForJgit;
|
/***/ public String indexFileIsTooLargeForJgit;
|
||||||
/***/ public String indexSignatureIsInvalid;
|
/***/ public String indexSignatureIsInvalid;
|
||||||
|
|
|
@ -139,9 +139,8 @@ public class PackWriter {
|
||||||
private static final int PACK_VERSION_GENERATED = 2;
|
private static final int PACK_VERSION_GENERATED = 2;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private final List<ObjectToPack> objectsLists[] = new List[Constants.OBJ_TAG + 1];
|
private final BlockList<ObjectToPack> objectsLists[] = new BlockList[Constants.OBJ_TAG + 1];
|
||||||
{
|
{
|
||||||
objectsLists[0] = Collections.<ObjectToPack> emptyList();
|
|
||||||
objectsLists[Constants.OBJ_COMMIT] = new BlockList<ObjectToPack>();
|
objectsLists[Constants.OBJ_COMMIT] = new BlockList<ObjectToPack>();
|
||||||
objectsLists[Constants.OBJ_TREE] = new BlockList<ObjectToPack>();
|
objectsLists[Constants.OBJ_TREE] = new BlockList<ObjectToPack>();
|
||||||
objectsLists[Constants.OBJ_BLOB] = new BlockList<ObjectToPack>();
|
objectsLists[Constants.OBJ_BLOB] = new BlockList<ObjectToPack>();
|
||||||
|
@ -412,8 +411,12 @@ public void setTagTargets(Set<ObjectId> objects) {
|
||||||
public long getObjectCount() throws IOException {
|
public long getObjectCount() throws IOException {
|
||||||
if (stats.totalObjects == 0) {
|
if (stats.totalObjects == 0) {
|
||||||
long objCnt = 0;
|
long objCnt = 0;
|
||||||
for (List<ObjectToPack> list : objectsLists)
|
|
||||||
objCnt += list.size();
|
objCnt += objectsLists[Constants.OBJ_COMMIT].size();
|
||||||
|
objCnt += objectsLists[Constants.OBJ_TREE].size();
|
||||||
|
objCnt += objectsLists[Constants.OBJ_BLOB].size();
|
||||||
|
objCnt += objectsLists[Constants.OBJ_TAG].size();
|
||||||
|
|
||||||
for (CachedPack pack : cachedPacks)
|
for (CachedPack pack : cachedPacks)
|
||||||
objCnt += pack.getObjectCount();
|
objCnt += pack.getObjectCount();
|
||||||
return objCnt;
|
return objCnt;
|
||||||
|
@ -590,11 +593,16 @@ public void writeIndex(final OutputStream indexStream) throws IOException {
|
||||||
private List<ObjectToPack> sortByName() {
|
private List<ObjectToPack> sortByName() {
|
||||||
if (sortedByName == null) {
|
if (sortedByName == null) {
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
for (List<ObjectToPack> list : objectsLists)
|
cnt += objectsLists[Constants.OBJ_COMMIT].size();
|
||||||
cnt += list.size();
|
cnt += objectsLists[Constants.OBJ_TREE].size();
|
||||||
|
cnt += objectsLists[Constants.OBJ_BLOB].size();
|
||||||
|
cnt += objectsLists[Constants.OBJ_TAG].size();
|
||||||
|
|
||||||
sortedByName = new BlockList<ObjectToPack>(cnt);
|
sortedByName = new BlockList<ObjectToPack>(cnt);
|
||||||
for (List<ObjectToPack> list : objectsLists)
|
sortedByName.addAll(objectsLists[Constants.OBJ_COMMIT]);
|
||||||
sortedByName.addAll(list);
|
sortedByName.addAll(objectsLists[Constants.OBJ_TREE]);
|
||||||
|
sortedByName.addAll(objectsLists[Constants.OBJ_BLOB]);
|
||||||
|
sortedByName.addAll(objectsLists[Constants.OBJ_TAG]);
|
||||||
Collections.sort(sortedByName);
|
Collections.sort(sortedByName);
|
||||||
}
|
}
|
||||||
return sortedByName;
|
return sortedByName;
|
||||||
|
@ -707,20 +715,29 @@ public void release() {
|
||||||
|
|
||||||
private void searchForReuse(ProgressMonitor monitor) throws IOException {
|
private void searchForReuse(ProgressMonitor monitor) throws IOException {
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
for (List<ObjectToPack> list : objectsLists)
|
cnt += objectsLists[Constants.OBJ_COMMIT].size();
|
||||||
cnt += list.size();
|
cnt += objectsLists[Constants.OBJ_TREE].size();
|
||||||
|
cnt += objectsLists[Constants.OBJ_BLOB].size();
|
||||||
|
cnt += objectsLists[Constants.OBJ_TAG].size();
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
monitor.beginTask(JGitText.get().searchForReuse, cnt);
|
monitor.beginTask(JGitText.get().searchForReuse, cnt);
|
||||||
for (List<ObjectToPack> list : objectsLists) {
|
searchForReuse(monitor, objectsLists[Constants.OBJ_COMMIT]);
|
||||||
pruneCurrentObjectList = false;
|
searchForReuse(monitor, objectsLists[Constants.OBJ_TREE]);
|
||||||
reuseSupport.selectObjectRepresentation(this, monitor, list);
|
searchForReuse(monitor, objectsLists[Constants.OBJ_BLOB]);
|
||||||
if (pruneCurrentObjectList)
|
searchForReuse(monitor, objectsLists[Constants.OBJ_TAG]);
|
||||||
pruneEdgesFromObjectList(list);
|
|
||||||
}
|
|
||||||
monitor.endTask();
|
monitor.endTask();
|
||||||
stats.timeSearchingForReuse = System.currentTimeMillis() - start;
|
stats.timeSearchingForReuse = System.currentTimeMillis() - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void searchForReuse(ProgressMonitor monitor, List<ObjectToPack> list)
|
||||||
|
throws IOException, MissingObjectException {
|
||||||
|
pruneCurrentObjectList = false;
|
||||||
|
reuseSupport.selectObjectRepresentation(this, monitor, list);
|
||||||
|
if (pruneCurrentObjectList)
|
||||||
|
pruneEdgesFromObjectList(list);
|
||||||
|
}
|
||||||
|
|
||||||
private void searchForDeltas(ProgressMonitor monitor)
|
private void searchForDeltas(ProgressMonitor monitor)
|
||||||
throws MissingObjectException, IncorrectObjectTypeException,
|
throws MissingObjectException, IncorrectObjectTypeException,
|
||||||
IOException {
|
IOException {
|
||||||
|
@ -1472,25 +1489,14 @@ public void addObject(final RevObject object)
|
||||||
addObject(object, 0);
|
addObject(object, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addObject(final RevObject object, final int pathHashCode)
|
private void addObject(final RevObject object, final int pathHashCode) {
|
||||||
throws IncorrectObjectTypeException {
|
|
||||||
final ObjectToPack otp;
|
final ObjectToPack otp;
|
||||||
if (reuseSupport != null)
|
if (reuseSupport != null)
|
||||||
otp = reuseSupport.newObjectToPack(object);
|
otp = reuseSupport.newObjectToPack(object);
|
||||||
else
|
else
|
||||||
otp = new ObjectToPack(object);
|
otp = new ObjectToPack(object);
|
||||||
otp.setPathHash(pathHashCode);
|
otp.setPathHash(pathHashCode);
|
||||||
|
objectsLists[object.getType()].add(otp);
|
||||||
try {
|
|
||||||
objectsLists[object.getType()].add(otp);
|
|
||||||
} catch (ArrayIndexOutOfBoundsException x) {
|
|
||||||
throw new IncorrectObjectTypeException(object,
|
|
||||||
JGitText.get().incorrectObjectType_COMMITnorTREEnorBLOBnorTAG);
|
|
||||||
} catch (UnsupportedOperationException x) {
|
|
||||||
// index pointing to "dummy" empty list
|
|
||||||
throw new IncorrectObjectTypeException(object,
|
|
||||||
JGitText.get().incorrectObjectType_COMMITnorTREEnorBLOBnorTAG);
|
|
||||||
}
|
|
||||||
objectsMap.add(otp);
|
objectsMap.add(otp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue