Browse Source

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>
stable-0.12
Shawn O. Pearce 14 years ago
parent
commit
0be24ebf33
  1. 1
      org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties
  2. 1
      org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
  3. 64
      org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

1
org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties

@ -214,7 +214,6 @@ improperlyPaddedBase64Input=Improperly padded Base64 input.
inMemoryBufferLimitExceeded=In-memory buffer limit exceeded
incorrectHashFor=Incorrect hash for {0}; computed {1} as a {2} from {3} bytes.
incorrectOBJECT_ID_LENGTH=Incorrect OBJECT_ID_LENGTH.
incorrectObjectType_COMMITnorTREEnorBLOBnorTAG=COMMIT nor TREE nor BLOB nor TAG
indexFileIsInUse=Index file is in use
indexFileIsTooLargeForJgit=Index file is too large for jgit
indexSignatureIsInvalid=Index signature is invalid: {0}

1
org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java

@ -274,7 +274,6 @@ public class JGitText extends TranslationBundle {
/***/ public String inMemoryBufferLimitExceeded;
/***/ public String incorrectHashFor;
/***/ public String incorrectOBJECT_ID_LENGTH;
/***/ public String incorrectObjectType_COMMITnorTREEnorBLOBnorTAG;
/***/ public String indexFileIsInUse;
/***/ public String indexFileIsTooLargeForJgit;
/***/ public String indexSignatureIsInvalid;

64
org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

@ -139,9 +139,8 @@ public class PackWriter {
private static final int PACK_VERSION_GENERATED = 2;
@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_TREE] = new BlockList<ObjectToPack>();
objectsLists[Constants.OBJ_BLOB] = new BlockList<ObjectToPack>();
@ -412,8 +411,12 @@ public class PackWriter {
public long getObjectCount() throws IOException {
if (stats.totalObjects == 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)
objCnt += pack.getObjectCount();
return objCnt;
@ -590,11 +593,16 @@ public class PackWriter {
private List<ObjectToPack> sortByName() {
if (sortedByName == null) {
int cnt = 0;
for (List<ObjectToPack> list : objectsLists)
cnt += list.size();
cnt += objectsLists[Constants.OBJ_COMMIT].size();
cnt += objectsLists[Constants.OBJ_TREE].size();
cnt += objectsLists[Constants.OBJ_BLOB].size();
cnt += objectsLists[Constants.OBJ_TAG].size();
sortedByName = new BlockList<ObjectToPack>(cnt);
for (List<ObjectToPack> list : objectsLists)
sortedByName.addAll(list);
sortedByName.addAll(objectsLists[Constants.OBJ_COMMIT]);
sortedByName.addAll(objectsLists[Constants.OBJ_TREE]);
sortedByName.addAll(objectsLists[Constants.OBJ_BLOB]);
sortedByName.addAll(objectsLists[Constants.OBJ_TAG]);
Collections.sort(sortedByName);
}
return sortedByName;
@ -707,20 +715,29 @@ public class PackWriter {
private void searchForReuse(ProgressMonitor monitor) throws IOException {
int cnt = 0;
for (List<ObjectToPack> list : objectsLists)
cnt += list.size();
cnt += objectsLists[Constants.OBJ_COMMIT].size();
cnt += objectsLists[Constants.OBJ_TREE].size();
cnt += objectsLists[Constants.OBJ_BLOB].size();
cnt += objectsLists[Constants.OBJ_TAG].size();
long start = System.currentTimeMillis();
monitor.beginTask(JGitText.get().searchForReuse, cnt);
for (List<ObjectToPack> list : objectsLists) {
pruneCurrentObjectList = false;
reuseSupport.selectObjectRepresentation(this, monitor, list);
if (pruneCurrentObjectList)
pruneEdgesFromObjectList(list);
}
searchForReuse(monitor, objectsLists[Constants.OBJ_COMMIT]);
searchForReuse(monitor, objectsLists[Constants.OBJ_TREE]);
searchForReuse(monitor, objectsLists[Constants.OBJ_BLOB]);
searchForReuse(monitor, objectsLists[Constants.OBJ_TAG]);
monitor.endTask();
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)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
@ -1472,25 +1489,14 @@ public class PackWriter {
addObject(object, 0);
}
private void addObject(final RevObject object, final int pathHashCode)
throws IncorrectObjectTypeException {
private void addObject(final RevObject object, final int pathHashCode) {
final ObjectToPack otp;
if (reuseSupport != null)
otp = reuseSupport.newObjectToPack(object);
else
otp = new ObjectToPack(object);
otp.setPathHash(pathHashCode);
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);
}
objectsLists[object.getType()].add(otp);
objectsMap.add(otp);
}

Loading…
Cancel
Save