dfs: Shrink DfsPackDescription.sizeMap storage
Using a HashMap is overkill for this storage. PackExt is a
constrained type that permits no more than 32 unique values in the JVM.
Each is assigned a unique index (getPosition), which can be used as
indexes in a simple long[].
Change-Id: Ib8e3b2db15d3fde28989b6f4b9897f8a7bb36f3b
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java
index dc68d57..86a0489 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java
@@ -45,8 +45,7 @@
import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Arrays;
import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
import org.eclipse.jgit.internal.storage.pack.PackExt;
@@ -62,25 +61,15 @@
*/
public class DfsPackDescription implements Comparable<DfsPackDescription> {
private final DfsRepositoryDescription repoDesc;
-
private final String packName;
-
private PackSource packSource;
-
private long lastModified;
-
- private final Map<PackExt, Long> sizeMap;
-
+ private long[] sizeMap;
private long objectCount;
-
private long deltaCount;
-
private PackStatistics stats;
-
private int extensions;
-
private int indexVersion;
-
private long estimatedPackSize;
/**
@@ -102,7 +91,7 @@
this.repoDesc = repoDesc;
int dot = name.lastIndexOf('.');
this.packName = (dot < 0) ? name : name.substring(0, dot);
- this.sizeMap = new HashMap<>(PackExt.values().length * 2);
+ this.sizeMap = new long[PackExt.values().length];
}
/** @return description of the repository. */
@@ -186,7 +175,11 @@
* @return {@code this}
*/
public DfsPackDescription setFileSize(PackExt ext, long bytes) {
- sizeMap.put(ext, Long.valueOf(Math.max(0, bytes)));
+ int i = ext.getPosition();
+ if (i >= sizeMap.length) {
+ sizeMap = Arrays.copyOf(sizeMap, i + 1);
+ }
+ sizeMap[i] = Math.max(0, bytes);
return this;
}
@@ -196,8 +189,8 @@
* @return size of the file, in bytes. If 0 the file size is not yet known.
*/
public long getFileSize(PackExt ext) {
- Long size = sizeMap.get(ext);
- return size == null ? 0 : size.longValue();
+ int i = ext.getPosition();
+ return i < sizeMap.length ? sizeMap[i] : 0;
}
/**