Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/RevisionLookup.java @ 628:6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 22 May 2013 15:52:31 +0200 |
parents | 46f29b73e51e |
children |
comparison
equal
deleted
inserted
replaced
627:5153eb73b18d | 628:6526d8adbc0f |
---|---|
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; | 19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; |
20 | 20 |
21 import java.util.Arrays; | 21 import java.util.Arrays; |
22 | 22 |
23 import org.tmatesoft.hg.core.Nodeid; | 23 import org.tmatesoft.hg.core.Nodeid; |
24 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | |
25 import org.tmatesoft.hg.repo.HgInvalidRevisionException; | |
24 import org.tmatesoft.hg.repo.HgRevisionMap; | 26 import org.tmatesoft.hg.repo.HgRevisionMap; |
27 import org.tmatesoft.hg.repo.HgRuntimeException; | |
25 | 28 |
26 /** | 29 /** |
27 * Lite alternative to {@link HgRevisionMap}, to speed up nodeid to index conversion without consuming too much memory. | 30 * Lite alternative to {@link HgRevisionMap}, to speed up nodeid to index conversion without consuming too much memory. |
28 * E.g. for a 100k revisions, {@link HgRevisionMap} consumes 3 * (N * sizeof(int)) for indexes plus 48 bytes per | 31 * E.g. for a 100k revisions, {@link HgRevisionMap} consumes 3 * (N * sizeof(int)) for indexes plus 48 bytes per |
29 * Nodeid instance, total (12+48)*N = 6 mb of memory. {RevisionLookup} instead keeps only Nodeid hashes, (N * sizeof(int) = 400 kb), | 32 * Nodeid instance, total (12+48)*N = 6 mb of memory. {RevisionLookup} instead keeps only Nodeid hashes, (N * sizeof(int) = 400 kb), |
40 public RevisionLookup(RevlogStream stream) { | 43 public RevisionLookup(RevlogStream stream) { |
41 assert stream != null; | 44 assert stream != null; |
42 content = stream; | 45 content = stream; |
43 } | 46 } |
44 | 47 |
45 public static RevisionLookup createFor(RevlogStream stream) { | 48 public static RevisionLookup createFor(RevlogStream stream) throws HgRuntimeException { |
46 RevisionLookup rv = new RevisionLookup(stream); | 49 RevisionLookup rv = new RevisionLookup(stream); |
47 int revCount = stream.revisionCount(); | 50 int revCount = stream.revisionCount(); |
48 rv.prepare(revCount); | 51 rv.prepare(revCount); |
49 if (revCount > 0) { | 52 if (revCount > 0) { |
50 stream.iterate(0, revCount - 1, false, rv); | 53 stream.iterate(0, revCount - 1, false, rv); |
60 nodeidHashes[index] = Nodeid.hashCode(nodeid); | 63 nodeidHashes[index] = Nodeid.hashCode(nodeid); |
61 } | 64 } |
62 public void next(int index, Nodeid nodeid) { | 65 public void next(int index, Nodeid nodeid) { |
63 nodeidHashes[index] = nodeid.hashCode(); | 66 nodeidHashes[index] = nodeid.hashCode(); |
64 } | 67 } |
65 public int findIndex(Nodeid nodeid) { | 68 public int findIndex(Nodeid nodeid) throws HgInvalidControlFileException, HgInvalidRevisionException { |
66 final int hash = nodeid.hashCode(); | 69 final int hash = nodeid.hashCode(); |
67 for (int i = 0; i < nodeidHashes.length; i++) { | 70 for (int i = 0; i < nodeidHashes.length; i++) { |
68 if (nodeidHashes[i] == hash) { | 71 if (nodeidHashes[i] == hash) { |
69 byte[] nodeidAtI = content.nodeid(i); | 72 byte[] nodeidAtI = content.nodeid(i); |
70 if (nodeid.equalsTo(nodeidAtI)) { | 73 if (nodeid.equalsTo(nodeidAtI)) { |