summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2017-07-19 05:41:31 -0700
committerShawn Pearce <spearce@spearce.org>2017-07-19 05:45:15 -0700
commit90a957c9472f82ff86c6b792dc6292c41052bc6c (patch)
treefea8606536d105806b9be3f7617b8aca42596861
parentda7671fcd5593431c9a31c9e005565217b44fe10 (diff)
downloadjgit-90a957c9472f82ff86c6b792dc6292c41052bc6c.tar.gz
jgit-90a957c9472f82ff86c6b792dc6292c41052bc6c.zip
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
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java27
1 files changed, 10 insertions, 17 deletions
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 dc68d5785b..86a04893b7 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 @@ package org.eclipse.jgit.internal.storage.dfs;
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 @@ import org.eclipse.jgit.storage.pack.PackStatistics;
*/
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 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> {
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 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> {
* @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 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> {
* @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;
}
/**