{"thread":{"id":"16641","subject":"[EGIT PATCH] Cache values of symbolic refs in RefDatabase","startedAt":"2008-12-08T21:48:56Z","lastAt":"2008-12-08T21:48:56Z","messageCount":1,"participants":["Robin Rosenberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"97387","messageId":"1228772936-2447-1-git-send-email-robin.rosenberg@dewire.com","threadId":"16641","inReplyTo":null,"subject":"[EGIT PATCH] Cache values of symbolic refs in RefDatabase","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-12-08T21:48:56Z","receivedAt":"2008-12-08T21:48:56Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"This way we avoid reading refs if the timestamp has not changed. This\nreduced the number of opens for reading symbolic refs like HEAD.\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../src/org/spearce/jgit/lib/RefDatabase.java      |   19 ++++++++++++++++---\n 1 files changed, 16 insertions(+), 3 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java\nindex 494aecb..4cf6e08 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java\n@@ -69,6 +69,7 @@\n \n \tprivate Map<String, Ref> looseRefs;\n \tprivate Map<String, Long> looseRefsMTime;\n+\tprivate Map<String, String> looseSymRefs;\n \n \tprivate final File packedRefsFile;\n \n@@ -96,6 +97,7 @@ void clearCache() {\n \t\tlooseRefs = new HashMap<String, Ref>();\n \t\tlooseRefsMTime = new HashMap<String, Long>();\n \t\tpackedRefs = new HashMap<String, Ref>();\n+\t\tlooseSymRefs = new HashMap<String, String>();\n \t\tpackedRefsLastModified = 0;\n \t\tpackedRefsLength = 0;\n \t}\n@@ -348,15 +350,26 @@ private Ref readRefBasic(final String origName, final String name, final int dep\n \t\t\treturn ref;\n \t\t}\n \n-\t\tfinal String line;\n+\t\tString line = null;\n \t\ttry {\n-\t\t\tline = readLine(loose);\n+\t\t\tLong cachedlastModified = looseRefsMTime.get(name);\n+\t\t\tif (cachedlastModified != null && cachedlastModified == mtime) {\n+\t\t\t\tline = looseSymRefs.get(name);\n+\t\t\t}\n+\t\t\tif (line == null) {\n+\t\t\t\tline = readLine(loose);\n+\t\t\t\tlooseRefsMTime.put(name, mtime);\n+\t\t\t\tlooseSymRefs.put(name, line);\n+\t\t\t}\n \t\t} catch (FileNotFoundException notLoose) {\n \t\t\treturn packedRefs.get(name);\n \t\t}\n \n-\t\tif (line == null || line.length() == 0)\n+\t\tif (line == null || line.length() == 0) {\n+\t\t\tlooseRefs.remove(origName);\n+\t\t\tlooseRefsMTime.remove(origName);\n \t\t\treturn new Ref(Ref.Storage.LOOSE, origName, name, null);\n+\t\t}\n \n \t\tif (line.startsWith(\"ref: \")) {\n \t\t\tif (depth >= 5) {\n-- \n1.6.0.3.640.g6331a\n"}]}