# HG changeset patch # User Artem Tikhomirov # Date 1367859184 -7200 # Node ID c3505001a42ab4651c026f6ce01d0b533827b220 # Parent 707b5c7c6fa4bef651d465e17eecff54ec9ae898 Use nodeid reverse lookup speedup cache for #isKnown, if available diff -r 707b5c7c6fa4 -r c3505001a42a src/org/tmatesoft/hg/repo/Revlog.java --- a/src/org/tmatesoft/hg/repo/Revlog.java Mon May 06 18:29:57 2013 +0200 +++ b/src/org/tmatesoft/hg/repo/Revlog.java Mon May 06 18:53:04 2013 +0200 @@ -150,15 +150,7 @@ * @throws HgRuntimeException subclass thereof to indicate issues with the library. Runtime exception */ public final int getRevisionIndex(Nodeid nid) throws HgRuntimeException { - int revision; - if (useRevisionLookup) { - if (revisionLookup == null) { - revisionLookup = RevisionLookup.createFor(content); - } - revision = revisionLookup.findIndex(nid); - } else { - revision = content.findRevisionIndex(nid); - } + final int revision = doFindWithCache(nid); if (revision == BAD_REVISION) { // using toString() to identify revlog. HgDataFile.toString includes path, HgManifest and HgChangelog instances // are fine with default (class name) @@ -168,6 +160,17 @@ return revision; } + private int doFindWithCache(Nodeid nid) { + if (useRevisionLookup) { + if (revisionLookup == null) { + revisionLookup = RevisionLookup.createFor(content); + } + return revisionLookup.findIndex(nid); + } else { + return content.findRevisionIndex(nid); + } + } + /** * Note, {@link Nodeid#NULL} nodeid is not reported as known in any revlog. * @@ -176,7 +179,7 @@ * @throws HgRuntimeException subclass thereof to indicate issues with the library. Runtime exception */ public final boolean isKnown(Nodeid nodeid) throws HgRuntimeException { - final int rn = content.findRevisionIndex(nodeid); + final int rn = doFindWithCache(nodeid); if (BAD_REVISION == rn) { return false; }