Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/Metadata.java @ 694:7efabe0cddcf
Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Mon, 05 Aug 2013 17:42:10 +0200 |
| parents | e3717fc7d26f |
| children |
comparison
equal
deleted
inserted
replaced
| 693:32b0d19e8aba | 694:7efabe0cddcf |
|---|---|
| 14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
| 15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
| 16 */ | 16 */ |
| 17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
| 18 | 18 |
| 19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; | |
| 19 import static org.tmatesoft.hg.util.LogFacility.Severity.Error; | 20 import static org.tmatesoft.hg.util.LogFacility.Severity.Error; |
| 20 | 21 |
| 21 import java.io.ByteArrayOutputStream; | 22 import java.io.ByteArrayOutputStream; |
| 22 import java.io.IOException; | 23 import java.io.IOException; |
| 23 import java.util.ArrayList; | 24 import java.util.ArrayList; |
| 48 private final IntMap<Metadata.Record> entries = new IntMap<Metadata.Record>(5); | 49 private final IntMap<Metadata.Record> entries = new IntMap<Metadata.Record>(5); |
| 49 | 50 |
| 50 private final Metadata.Record NONE = new Record(-1, null); // don't want statics | 51 private final Metadata.Record NONE = new Record(-1, null); // don't want statics |
| 51 | 52 |
| 52 private final LogFacility log; | 53 private final LogFacility log; |
| 54 | |
| 55 private int lastRevRead = NO_REVISION; | |
| 53 | 56 |
| 54 public Metadata(SessionContext.Source sessionCtx) { | 57 public Metadata(SessionContext.Source sessionCtx) { |
| 55 log = sessionCtx.getSessionContext().getLog(); | 58 log = sessionCtx.getSessionContext().getLog(); |
| 56 } | 59 } |
| 57 | 60 |
| 58 // true when there's metadata for given revision | 61 /** |
| 62 * @return <code>true</code> when there's metadata for given revision | |
| 63 */ | |
| 59 public boolean known(int revision) { | 64 public boolean known(int revision) { |
| 60 Metadata.Record i = entries.get(revision); | 65 Metadata.Record i = entries.get(revision); |
| 61 return i != null && NONE != i; | 66 return i != null && NONE != i; |
| 62 } | 67 } |
| 63 | 68 |
| 64 // true when revision has been checked for metadata presence. | 69 /** |
| 70 * @return <code>true</code> when revision has been checked for metadata presence. | |
| 71 */ | |
| 65 public boolean checked(int revision) { | 72 public boolean checked(int revision) { |
| 66 return entries.containsKey(revision); | 73 return entries.containsKey(revision); |
| 67 } | 74 } |
| 68 | 75 |
| 69 // true when revision has been checked and found not having any metadata | 76 // true when revision has been checked and found not having any metadata |
| 70 public boolean none(int revision) { | 77 public boolean none(int revision) { |
| 71 Metadata.Record i = entries.get(revision); | 78 Metadata.Record i = entries.get(revision); |
| 72 return i == NONE; | 79 return i == NONE; |
| 80 } | |
| 81 | |
| 82 /** | |
| 83 * Get the greatest revision index visited so far. | |
| 84 * Note, doesn't imply all revisions up to this has been visited. | |
| 85 */ | |
| 86 public int lastRevisionRead() { | |
| 87 return lastRevRead; | |
| 73 } | 88 } |
| 74 | 89 |
| 75 // mark revision as having no metadata. | 90 // mark revision as having no metadata. |
| 76 void recordNone(int revision) { | 91 void recordNone(int revision) { |
| 77 Metadata.Record i = entries.get(revision); | 92 Metadata.Record i = entries.get(revision); |
| 96 /** | 111 /** |
| 97 * @return <code>true</code> if metadata has been found | 112 * @return <code>true</code> if metadata has been found |
| 98 */ | 113 */ |
| 99 public boolean tryRead(int revisionNumber, DataAccess data) throws IOException, HgInvalidControlFileException { | 114 public boolean tryRead(int revisionNumber, DataAccess data) throws IOException, HgInvalidControlFileException { |
| 100 final int daLength = data.length(); | 115 final int daLength = data.length(); |
| 116 if (lastRevRead == NO_REVISION || revisionNumber > lastRevRead) { | |
| 117 lastRevRead = revisionNumber; | |
| 118 } | |
| 101 if (daLength < 4 || data.readByte() != 1 || data.readByte() != 10) { | 119 if (daLength < 4 || data.readByte() != 1 || data.readByte() != 10) { |
| 102 recordNone(revisionNumber); | 120 recordNone(revisionNumber); |
| 103 return false; | 121 return false; |
| 104 } else { | 122 } else { |
| 105 ArrayList<MetadataEntry> _metadata = new ArrayList<MetadataEntry>(); | 123 ArrayList<MetadataEntry> _metadata = new ArrayList<MetadataEntry>(); |
