From eb64ccad6d0ec1c8dbe4419c6e4ff564d1fac167 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 7 Sep 2010 18:18:55 -0700 Subject: [PATCH] Correctly name DeltaBaseCache This class is used only to cache the unpacked form of an object that was used as a base for another object. The theory goes that if an object is used as a delta base for A, it will probably also be a delta base for B, C, D, E, etc. and therefore having an unpacked copy of it on hand will make delta resolution for the others very fast. However since objects are usually only accessed once, we don't want to cache everything we unpack, just things that we are likely to need again. The only things we need again are the delta bases. Hence, its a delta base cache. This gets us the class name UnpackedObjectCache back, so we can use it to actually create a cache of unpacked object information. Change-Id: I121f356cf4eca7b80126497264eac22bd5825a1d Signed-off-by: Shawn O. Pearce --- ...npackedObjectCache.java => DeltaBaseCache.java} | 4 ++-- .../org/eclipse/jgit/storage/file/PackFile.java | 14 +++----------- .../org/eclipse/jgit/storage/file/WindowCache.java | 2 +- .../jgit/storage/file/WindowCacheConfig.java | 4 ++-- 4 files changed, 8 insertions(+), 16 deletions(-) rename org.eclipse.jgit/src/org/eclipse/jgit/storage/file/{UnpackedObjectCache.java => DeltaBaseCache.java} (98%) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/UnpackedObjectCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/DeltaBaseCache.java similarity index 98% rename from org.eclipse.jgit/src/org/eclipse/jgit/storage/file/UnpackedObjectCache.java rename to org.eclipse.jgit/src/org/eclipse/jgit/storage/file/DeltaBaseCache.java index 92f482425..8b548242b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/UnpackedObjectCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/DeltaBaseCache.java @@ -45,7 +45,7 @@ import java.lang.ref.SoftReference; -class UnpackedObjectCache { +class DeltaBaseCache { private static final int CACHE_SZ = 1024; private static final SoftReference DEAD; @@ -164,7 +164,7 @@ private static void clearEntry(final Slot e) { e.sz = 0; } - private UnpackedObjectCache() { + private DeltaBaseCache() { throw new UnsupportedOperationException(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java index ed159ef38..523911162 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java @@ -220,7 +220,7 @@ void resolve(Set matches, AbbreviatedObjectId id, int matchLimit) * Close the resources utilized by this repository */ public void close() { - UnpackedObjectCache.purge(this); + DeltaBaseCache.purge(this); WindowCache.purge(this); synchronized (this) { loadedIdx = null; @@ -274,14 +274,6 @@ ObjectId findObjectForOffset(final long offset) throws IOException { return getReverseIdx().findObject(offset); } - private final UnpackedObjectCache.Entry readCache(final long position) { - return UnpackedObjectCache.get(this, position); - } - - private final void saveCache(final long position, final byte[] data, final int type) { - UnpackedObjectCache.store(this, position, data, type); - } - private final byte[] decompress(final long position, final long totalSize, final WindowCursor curs) throws IOException, DataFormatException { final byte[] dstbuf = new byte[(int) totalSize]; @@ -700,7 +692,7 @@ private ObjectLoader loadDelta(long posSelf, int hdrLen, long sz, byte[] data; int type; - UnpackedObjectCache.Entry e = readCache(posBase); + DeltaBaseCache.Entry e = DeltaBaseCache.get(this, posBase); if (e != null) { data = e.data; type = e.type; @@ -715,7 +707,7 @@ private ObjectLoader loadDelta(long posSelf, int hdrLen, long sz, } data = p.getCachedBytes(); type = p.getType(); - saveCache(posBase, data, type); + DeltaBaseCache.store(this, posBase, data, type); } // At this point we have the base, and its small, and the delta diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCache.java index 68fa19120..f533af48c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCache.java @@ -187,7 +187,7 @@ public static void reconfigure(final WindowCacheConfig cfg) { oc.removeAll(); cache = nc; streamFileThreshold = cfg.getStreamFileThreshold(); - UnpackedObjectCache.reconfigure(cfg); + DeltaBaseCache.reconfigure(cfg); } static int getStreamFileThreshold() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java index 90ea376b5..95ec6f7c7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java @@ -146,7 +146,7 @@ public void setPackedGitMMAP(final boolean usemmap) { } /** - * @return maximum number of bytes to cache in {@link UnpackedObjectCache} + * @return maximum number of bytes to cache in {@link DeltaBaseCache} * for inflated, recently accessed objects, without delta chains. * Default 10 MB. */ @@ -157,7 +157,7 @@ public int getDeltaBaseCacheLimit() { /** * @param newLimit * maximum number of bytes to cache in - * {@link UnpackedObjectCache} for inflated, recently accessed + * {@link DeltaBaseCache} for inflated, recently accessed * objects, without delta chains. */ public void setDeltaBaseCacheLimit(final int newLimit) {