git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT PATCH] Cache values of symbolic refs in RefDatabase
Date: Mon,  8 Dec 2008 22:48:56 +0100	[thread overview]
Message-ID: <1228772936-2447-1-git-send-email-robin.rosenberg@dewire.com> (raw)

This way we avoid reading refs if the timestamp has not changed. This
reduced the number of opens for reading symbolic refs like HEAD.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/lib/RefDatabase.java      |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
index 494aecb..4cf6e08 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
@@ -69,6 +69,7 @@
 
 	private Map<String, Ref> looseRefs;
 	private Map<String, Long> looseRefsMTime;
+	private Map<String, String> looseSymRefs;
 
 	private final File packedRefsFile;
 
@@ -96,6 +97,7 @@ void clearCache() {
 		looseRefs = new HashMap<String, Ref>();
 		looseRefsMTime = new HashMap<String, Long>();
 		packedRefs = new HashMap<String, Ref>();
+		looseSymRefs = new HashMap<String, String>();
 		packedRefsLastModified = 0;
 		packedRefsLength = 0;
 	}
@@ -348,15 +350,26 @@ private Ref readRefBasic(final String origName, final String name, final int dep
 			return ref;
 		}
 
-		final String line;
+		String line = null;
 		try {
-			line = readLine(loose);
+			Long cachedlastModified = looseRefsMTime.get(name);
+			if (cachedlastModified != null && cachedlastModified == mtime) {
+				line = looseSymRefs.get(name);
+			}
+			if (line == null) {
+				line = readLine(loose);
+				looseRefsMTime.put(name, mtime);
+				looseSymRefs.put(name, line);
+			}
 		} catch (FileNotFoundException notLoose) {
 			return packedRefs.get(name);
 		}
 
-		if (line == null || line.length() == 0)
+		if (line == null || line.length() == 0) {
+			looseRefs.remove(origName);
+			looseRefsMTime.remove(origName);
 			return new Ref(Ref.Storage.LOOSE, origName, name, null);
+		}
 
 		if (line.startsWith("ref: ")) {
 			if (depth >= 5) {
-- 
1.6.0.3.640.g6331a

                 reply	other threads:[~2008-12-08 21:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1228772936-2447-1-git-send-email-robin.rosenberg@dewire.com \
    --to=robin.rosenberg@dewire.com \
    --cc=git@vger.kernel.org \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).