changeset 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 9e85feb93984
children 9d5cff8d7f67
files hgsubversion/maps.py
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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):