Browse Source

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
stable-4.9
Shawn Pearce 7 years ago
parent
commit
90a957c947
  1. 27
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java

27
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;
}
/**

Loading…
Cancel
Save