# HG changeset patch # User Mateusz Kwapich # Date 1418430754 28800 # Node ID 9a722b5246dff6819576b2b7f424fb62a8968405 # Parent 9e85feb9398461cee905d59040c4c3e9cf641bb1 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. diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -194,6 +194,7 @@ class RevMap(dict): def __init__(self, meta): dict.__init__(self) self.meta = meta + self._hashes = None if os.path.isfile(self.meta.revmap_file): self._load() @@ -201,7 +202,9 @@ class RevMap(dict): self._write() def hashes(self): - return dict((v, k) for (k, v) in self.iteritems()) + if self._hashes is None: + self._hashes = dict((v, k) for (k, v) in self.iteritems()) + return self._hashes def branchedits(self, branch, rev): check = lambda x: x[0][1] == branch and x[0][0] < rev.revnum @@ -256,6 +259,8 @@ class RevMap(dict): if revnum < self.meta.firstpulled or not self.meta.firstpulled: self.meta.firstpulled = revnum dict.__setitem__(self, (revnum, branch), ha) + if self._hashes is not None: + self._hashes[ha] = (revnum, branch) class FileMap(object):