Mercurial > hgsubversion
comparison hgsubversion/maps.py @ 1294:9a722b5246df
maps: cache hashes() for the revmap
This fix caches the hashes() results for revision map. For big
repos the revision map can be huge (>30MB) and this fix is saving us
some time (~0.7s per every subsequent call) by avoiding reversing rev
dictionary multiple times.
| author | Mateusz Kwapich <mitrandir@fb.com> |
|---|---|
| date | Fri, 12 Dec 2014 16:32:34 -0800 |
| parents | d07ccad28b1a |
| children | ecce8aef4b21 |
comparison
equal
deleted
inserted
replaced
| 1293:9e85feb93984 | 1294:9a722b5246df |
|---|---|
| 192 VERSION = 1 | 192 VERSION = 1 |
| 193 | 193 |
| 194 def __init__(self, meta): | 194 def __init__(self, meta): |
| 195 dict.__init__(self) | 195 dict.__init__(self) |
| 196 self.meta = meta | 196 self.meta = meta |
| 197 self._hashes = None | |
| 197 | 198 |
| 198 if os.path.isfile(self.meta.revmap_file): | 199 if os.path.isfile(self.meta.revmap_file): |
| 199 self._load() | 200 self._load() |
| 200 else: | 201 else: |
| 201 self._write() | 202 self._write() |
| 202 | 203 |
| 203 def hashes(self): | 204 def hashes(self): |
| 204 return dict((v, k) for (k, v) in self.iteritems()) | 205 if self._hashes is None: |
| 206 self._hashes = dict((v, k) for (k, v) in self.iteritems()) | |
| 207 return self._hashes | |
| 205 | 208 |
| 206 def branchedits(self, branch, rev): | 209 def branchedits(self, branch, rev): |
| 207 check = lambda x: x[0][1] == branch and x[0][0] < rev.revnum | 210 check = lambda x: x[0][1] == branch and x[0][0] < rev.revnum |
| 208 return sorted(filter(check, self.iteritems()), reverse=True) | 211 return sorted(filter(check, self.iteritems()), reverse=True) |
| 209 | 212 |
| 254 if revnum > self.meta.lastpulled or not self.meta.lastpulled: | 257 if revnum > self.meta.lastpulled or not self.meta.lastpulled: |
| 255 self.meta.lastpulled = revnum | 258 self.meta.lastpulled = revnum |
| 256 if revnum < self.meta.firstpulled or not self.meta.firstpulled: | 259 if revnum < self.meta.firstpulled or not self.meta.firstpulled: |
| 257 self.meta.firstpulled = revnum | 260 self.meta.firstpulled = revnum |
| 258 dict.__setitem__(self, (revnum, branch), ha) | 261 dict.__setitem__(self, (revnum, branch), ha) |
| 262 if self._hashes is not None: | |
| 263 self._hashes[ha] = (revnum, branch) | |
| 259 | 264 |
| 260 | 265 |
| 261 class FileMap(object): | 266 class FileMap(object): |
| 262 | 267 |
| 263 VERSION = 1 | 268 VERSION = 1 |
