This uses more memory, but by having a WeakMap we allow the garbage collector to claim the memory if needed. This speeds up the history panel enormously, so that having the history pane connected to the selected resource is not a performance problem (except the first time the history of a resource in a projects is shown). Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx> --- .../src/org/spearce/jgit/lib/Repository.java | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java index 781ad90..f7c470d 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java @@ -25,6 +25,8 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.Map; +import java.util.WeakHashMap; import org.spearce.jgit.errors.IncorrectObjectTypeException; import org.spearce.jgit.errors.ObjectWritingException; @@ -45,6 +47,8 @@ public class Repository { private WindowCache windows; + private Map cache = new WeakHashMap(30000); + public Repository(final File d) throws IOException { gitDir = d.getAbsoluteFile(); objectsDir = new File(gitDir, "objects"); @@ -185,12 +189,19 @@ public class Repository { } public Commit mapCommit(final ObjectId id) throws IOException { + Commit ret = (Commit)cache.get(id); + if (ret != null) + return ret; + final ObjectLoader or = openObject(id); if (or == null) return null; final byte[] raw = or.getBytes(); - if (Constants.TYPE_COMMIT.equals(or.getType())) - return new Commit(this, id, raw); + if (Constants.TYPE_COMMIT.equals(or.getType())) { + ret = new Commit(this, id, raw); + cache.put(id, ret); + return ret; + } throw new IncorrectObjectTypeException(id, Constants.TYPE_COMMIT); } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html