comparison src/org/tmatesoft/hg/repo/Revlog.java @ 600:46f29b73e51e

Utilize RevisionLookup to speed-up getRevisionIndex of both manifest and changelog
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 03 May 2013 17:03:31 +0200
parents dd4f6311af52
children 8143c1f77d45
comparison
equal deleted inserted replaced
599:55b7987c1796 600:46f29b73e51e
28 import org.tmatesoft.hg.core.Nodeid; 28 import org.tmatesoft.hg.core.Nodeid;
29 import org.tmatesoft.hg.internal.DataAccess; 29 import org.tmatesoft.hg.internal.DataAccess;
30 import org.tmatesoft.hg.internal.Experimental; 30 import org.tmatesoft.hg.internal.Experimental;
31 import org.tmatesoft.hg.internal.IntMap; 31 import org.tmatesoft.hg.internal.IntMap;
32 import org.tmatesoft.hg.internal.Preview; 32 import org.tmatesoft.hg.internal.Preview;
33 import org.tmatesoft.hg.internal.RevisionLookup;
33 import org.tmatesoft.hg.internal.RevlogStream; 34 import org.tmatesoft.hg.internal.RevlogStream;
34 import org.tmatesoft.hg.util.Adaptable; 35 import org.tmatesoft.hg.util.Adaptable;
35 import org.tmatesoft.hg.util.ByteChannel; 36 import org.tmatesoft.hg.util.ByteChannel;
36 import org.tmatesoft.hg.util.CancelSupport; 37 import org.tmatesoft.hg.util.CancelSupport;
37 import org.tmatesoft.hg.util.CancelledException; 38 import org.tmatesoft.hg.util.CancelledException;
51 */ 52 */
52 abstract class Revlog { 53 abstract class Revlog {
53 54
54 private final HgRepository repo; 55 private final HgRepository repo;
55 protected final RevlogStream content; 56 protected final RevlogStream content;
56 57 protected final boolean useRevisionLookup;
57 protected Revlog(HgRepository hgRepo, RevlogStream contentStream) { 58 protected RevisionLookup revisionLookup;
59
60 protected Revlog(HgRepository hgRepo, RevlogStream contentStream, boolean needRevisionLookup) {
58 if (hgRepo == null) { 61 if (hgRepo == null) {
59 throw new IllegalArgumentException(); 62 throw new IllegalArgumentException();
60 } 63 }
61 if (contentStream == null) { 64 if (contentStream == null) {
62 throw new IllegalArgumentException(); 65 throw new IllegalArgumentException();
63 } 66 }
64 repo = hgRepo; 67 repo = hgRepo;
65 content = contentStream; 68 content = contentStream;
69 useRevisionLookup = needRevisionLookup;
66 } 70 }
67 71
68 // invalid Revlog 72 // invalid Revlog
69 protected Revlog(HgRepository hgRepo) { 73 protected Revlog(HgRepository hgRepo) {
70 repo = hgRepo; 74 repo = hgRepo;
71 content = null; 75 content = null;
76 useRevisionLookup = false;
72 } 77 }
73 78
74 public final HgRepository getRepo() { 79 public final HgRepository getRepo() {
75 return repo; 80 return repo;
76 } 81 }
143 * @param nid revision to look up 148 * @param nid revision to look up
144 * @return revision local index in this revlog 149 * @return revision local index in this revlog
145 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> 150 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
146 */ 151 */
147 public final int getRevisionIndex(Nodeid nid) throws HgRuntimeException { 152 public final int getRevisionIndex(Nodeid nid) throws HgRuntimeException {
148 int revision = content.findRevisionIndex(nid); 153 // final long t1 = System.nanoTime();
154 int revision;
155 if (useRevisionLookup) {
156 if (revisionLookup == null) {
157 revisionLookup = RevisionLookup.createFor(content);
158 }
159 revision = revisionLookup.findIndex(nid);
160 } else {
161 revision = content.findRevisionIndex(nid);
162 }
149 if (revision == BAD_REVISION) { 163 if (revision == BAD_REVISION) {
150 // using toString() to identify revlog. HgDataFile.toString includes path, HgManifest and HgChangelog instances 164 // using toString() to identify revlog. HgDataFile.toString includes path, HgManifest and HgChangelog instances
151 // are fine with default (class name) 165 // are fine with default (class name)
152 // Perhaps, more tailored description method would be suitable here 166 // Perhaps, more tailored description method would be suitable here
153 throw new HgInvalidRevisionException(String.format("Can't find revision %s in %s", nid.shortNotation(), this), nid, null); 167 throw new HgInvalidRevisionException(String.format("Can't find revision %s in %s", nid.shortNotation(), this), nid, null);
154 } 168 }
169 // final long t2 = System.nanoTime();
170 // System.out.printf("\tgetRevisionIndex(%s): %d us\n", nid.shortNotation(), (t2-t1)/1000);
155 return revision; 171 return revision;
156 } 172 }
157 173
158 /** 174 /**
159 * Note, {@link Nodeid#NULL} nodeid is not reported as known in any revlog. 175 * Note, {@link Nodeid#NULL} nodeid is not reported as known in any revlog.