summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2011-03-18 08:37:28 -0700
committerShawn O. Pearce <spearce@spearce.org>2011-04-01 17:40:33 -0400
commit0be24ebf33974d4f1512644608769cb82d1782ea (patch)
tree3c3c8c3c259a88328d65983e8ecfcfc436e5daab /org.eclipse.jgit
parent9f5bbb5dd41f87d6428eb49c021e00d8099d0c17 (diff)
downloadjgit-0be24ebf33974d4f1512644608769cb82d1782ea.tar.gz
jgit-0be24ebf33974d4f1512644608769cb82d1782ea.zip
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>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java64
3 files changed, 35 insertions, 31 deletions
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties
index b606bbb249..a19c9c41dd 100644
--- a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties
+++ b/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}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
index 5877b4f6a6..f86a8e5446 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
+++ b/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;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java
index bef5816b77..5f3599d8c2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java
+++ b/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);
}