Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/ManifestRevision.java @ 285:6dbbc53fc46d
Use Path instead of plain String for manifest file names
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 03 Sep 2011 21:46:13 +0200 |
parents | 3fbfce107f94 |
children | ee8264d80747 |
comparison
equal
deleted
inserted
replaced
284:7232b94f2ae3 | 285:6dbbc53fc46d |
---|---|
17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
18 | 18 |
19 import java.util.Collection; | 19 import java.util.Collection; |
20 import java.util.TreeMap; | 20 import java.util.TreeMap; |
21 | 21 |
22 import org.tmatesoft.hg.core.HgBadStateException; | |
22 import org.tmatesoft.hg.core.Nodeid; | 23 import org.tmatesoft.hg.core.Nodeid; |
23 import org.tmatesoft.hg.repo.HgManifest; | 24 import org.tmatesoft.hg.repo.HgManifest; |
25 import org.tmatesoft.hg.util.Path; | |
24 | 26 |
25 /** | 27 /** |
26 * Specific revision of the manifest. | 28 * Specific revision of the manifest. |
27 * Note, suited to keep single revision only ({@link #changeset()}). | 29 * Note, suited to keep single revision only ({@link #changeset()}). |
28 * | 30 * |
29 * @author Artem Tikhomirov | 31 * @author Artem Tikhomirov |
30 * @author TMate Software Ltd. | 32 * @author TMate Software Ltd. |
31 */ | 33 */ |
32 public final class ManifestRevision implements HgManifest.Inspector { | 34 public final class ManifestRevision implements HgManifest.Inspector2 { |
33 private final TreeMap<String, Nodeid> idsMap; | 35 private final TreeMap<Path, Nodeid> idsMap; |
34 private final TreeMap<String, String> flagsMap; | 36 private final TreeMap<Path, HgManifest.Flags> flagsMap; |
35 private final Pool<Nodeid> idsPool; | 37 private final Pool<Nodeid> idsPool; |
36 private final Pool<String> namesPool; | 38 private final Pool<Path> namesPool; |
37 private Nodeid changeset; | 39 private Nodeid changeset; |
38 private int changelogRev; | 40 private int changelogRev; |
39 | 41 |
40 // optional pools for effective management of nodeids and filenames (they are likely | 42 // optional pools for effective management of nodeids and filenames (they are likely |
41 // to be duplicated among different manifest revisions | 43 // to be duplicated among different manifest revisions |
42 public ManifestRevision(Pool<Nodeid> nodeidPool, Pool<String> filenamePool) { | 44 public ManifestRevision(Pool<Nodeid> nodeidPool, Pool<Path> filenamePool) { |
43 idsPool = nodeidPool; | 45 idsPool = nodeidPool; |
44 namesPool = filenamePool; | 46 namesPool = filenamePool; |
45 idsMap = new TreeMap<String, Nodeid>(); | 47 idsMap = new TreeMap<Path, Nodeid>(); |
46 flagsMap = new TreeMap<String, String>(); | 48 flagsMap = new TreeMap<Path, HgManifest.Flags>(); |
47 } | 49 } |
48 | 50 |
49 public Collection<String> files() { | 51 public Collection<Path> files() { |
50 return idsMap.keySet(); | 52 return idsMap.keySet(); |
51 } | 53 } |
52 | 54 |
53 public Nodeid nodeid(String fname) { | 55 public Nodeid nodeid(Path fname) { |
54 return idsMap.get(fname); | 56 return idsMap.get(fname); |
55 } | 57 } |
56 | 58 |
57 public String flags(String fname) { | 59 public HgManifest.Flags flags(Path fname) { |
58 return flagsMap.get(fname); | 60 return flagsMap.get(fname); |
59 } | 61 } |
60 | 62 |
61 /** | 63 /** |
62 * @return identifier of the changeset this manifest revision corresponds to. | 64 * @return identifier of the changeset this manifest revision corresponds to. |
70 } | 72 } |
71 | 73 |
72 // | 74 // |
73 | 75 |
74 public boolean next(Nodeid nid, String fname, String flags) { | 76 public boolean next(Nodeid nid, String fname, String flags) { |
77 throw new HgBadStateException(HgManifest.Inspector2.class.getName()); | |
78 } | |
79 | |
80 public boolean next(Nodeid nid, Path fname, HgManifest.Flags flags) { | |
75 if (namesPool != null) { | 81 if (namesPool != null) { |
76 fname = namesPool.unify(fname); | 82 fname = namesPool.unify(fname); |
77 } | 83 } |
78 if (idsPool != null) { | 84 if (idsPool != null) { |
79 nid = idsPool.unify(nid); | 85 nid = idsPool.unify(nid); |
80 } | 86 } |
81 idsMap.put(fname, nid); | 87 idsMap.put(fname, nid); |
82 if (flags != null) { | 88 if (flags != null) { |
83 // TreeMap$Entry takes 32 bytes. No reason to keep null for such price | 89 // TreeMap$Entry takes 32 bytes. No reason to keep null for such price |
84 // Perhaps, Map<String, Pair<Nodeid, String>> might be better solution | 90 // Alternatively, Map<Path, Pair<Nodeid, Flags>> might come as a solution |
91 // however, with low rate of elements with flags this would consume more memory | |
92 // than two distinct maps (sizeof(Pair) == 16). | |
93 // Map<Pair>: n*(32+16) | |
94 // 2 Maps: n*32 + m*32 <-- consumes more with m>n/2 | |
85 flagsMap.put(fname, flags); | 95 flagsMap.put(fname, flags); |
86 } | 96 } |
87 return true; | 97 return true; |
88 } | 98 } |
89 | 99 |