Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/Revlog.java @ 604:c3505001a42a
Use nodeid reverse lookup speedup cache for #isKnown, if available
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Mon, 06 May 2013 18:53:04 +0200 | 
| parents | 8143c1f77d45 | 
| children | 66f1cc23b906 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 603:707b5c7c6fa4 | 604:c3505001a42a | 
|---|---|
| 148 * @param nid revision to look up | 148 * @param nid revision to look up | 
| 149 * @return revision local index in this revlog | 149 * @return revision local index in this revlog | 
| 150 * @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> | 
| 151 */ | 151 */ | 
| 152 public final int getRevisionIndex(Nodeid nid) throws HgRuntimeException { | 152 public final int getRevisionIndex(Nodeid nid) throws HgRuntimeException { | 
| 153 int revision; | 153 final int revision = doFindWithCache(nid); | 
| 154 if (useRevisionLookup) { | |
| 155 if (revisionLookup == null) { | |
| 156 revisionLookup = RevisionLookup.createFor(content); | |
| 157 } | |
| 158 revision = revisionLookup.findIndex(nid); | |
| 159 } else { | |
| 160 revision = content.findRevisionIndex(nid); | |
| 161 } | |
| 162 if (revision == BAD_REVISION) { | 154 if (revision == BAD_REVISION) { | 
| 163 // using toString() to identify revlog. HgDataFile.toString includes path, HgManifest and HgChangelog instances | 155 // using toString() to identify revlog. HgDataFile.toString includes path, HgManifest and HgChangelog instances | 
| 164 // are fine with default (class name) | 156 // are fine with default (class name) | 
| 165 // Perhaps, more tailored description method would be suitable here | 157 // Perhaps, more tailored description method would be suitable here | 
| 166 throw new HgInvalidRevisionException(String.format("Can't find revision %s in %s", nid.shortNotation(), this), nid, null); | 158 throw new HgInvalidRevisionException(String.format("Can't find revision %s in %s", nid.shortNotation(), this), nid, null); | 
| 167 } | 159 } | 
| 168 return revision; | 160 return revision; | 
| 169 } | 161 } | 
| 170 | 162 | 
| 163 private int doFindWithCache(Nodeid nid) { | |
| 164 if (useRevisionLookup) { | |
| 165 if (revisionLookup == null) { | |
| 166 revisionLookup = RevisionLookup.createFor(content); | |
| 167 } | |
| 168 return revisionLookup.findIndex(nid); | |
| 169 } else { | |
| 170 return content.findRevisionIndex(nid); | |
| 171 } | |
| 172 } | |
| 173 | |
| 171 /** | 174 /** | 
| 172 * 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. | 
| 173 * | 176 * | 
| 174 * @param nodeid | 177 * @param nodeid | 
| 175 * @return <code>true</code> if revision is part of this revlog | 178 * @return <code>true</code> if revision is part of this revlog | 
| 176 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> | 179 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> | 
| 177 */ | 180 */ | 
| 178 public final boolean isKnown(Nodeid nodeid) throws HgRuntimeException { | 181 public final boolean isKnown(Nodeid nodeid) throws HgRuntimeException { | 
| 179 final int rn = content.findRevisionIndex(nodeid); | 182 final int rn = doFindWithCache(nodeid); | 
| 180 if (BAD_REVISION == rn) { | 183 if (BAD_REVISION == rn) { | 
| 181 return false; | 184 return false; | 
| 182 } | 185 } | 
| 183 if (rn < 0 || rn >= content.revisionCount()) { | 186 if (rn < 0 || rn >= content.revisionCount()) { | 
| 184 // Sanity check | 187 // Sanity check | 
