changeset 1253:c54214bb6c4e

maps: avoid O(n) property lookups on the node module The particular improvement we're interested in here is with loading the revmap. Loading a million-entry revmap goes from 3.82 seconds to 3.72.
author Siddharth Agarwal <sid0@fb.com>
date Sun, 02 Nov 2014 01:27:38 -0800
parents a321afbc3479
children d07ccad28b1a
files hgsubversion/maps.py
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/maps.py
+++ b/hgsubversion/maps.py
@@ -3,7 +3,7 @@
 import errno
 import os
 from mercurial import util as hgutil
-from mercurial import node
+from mercurial.node import bin, hex, nullid
 
 import svncommands
 import util
@@ -155,7 +155,7 @@ class Tags(dict):
                 break
             if not tag:
                 continue
-            dict.__setitem__(self, tag, node.bin(ha))
+            dict.__setitem__(self, tag, bin(ha))
         f.close()
 
     def _write(self):
@@ -170,7 +170,7 @@ class Tags(dict):
 
     def __contains__(self, tag):
         return (tag and dict.__contains__(self, tag)
-                and dict.__getitem__(self, tag) != node.nullid)
+                and dict.__getitem__(self, tag) != nullid)
 
     def __getitem__(self, tag):
         if tag and tag in self:
@@ -182,7 +182,7 @@ class Tags(dict):
             raise hgutil.Abort('tag cannot be empty')
         ha, revision = info
         f = open(self.meta.tagfile, 'a')
-        f.write('%s %s %s\n' % (node.hex(ha), revision, tag))
+        f.write('%s %s %s\n' % (hex(ha), revision, tag))
         f.close()
         dict.__setitem__(self, tag, ha)
 
@@ -235,7 +235,7 @@ class RevMap(dict):
                 lastpulled = revnum
             if revnum < firstpulled or not firstpulled:
                 firstpulled = revnum
-            dict.__setitem__(self, (revnum, branch), node.bin(ha))
+            dict.__setitem__(self, (revnum, branch), bin(ha))
         self.meta.lastpulled = lastpulled
         self.meta.firstpulled = firstpulled
 
@@ -248,7 +248,7 @@ class RevMap(dict):
         revnum, branch = key
         f = open(self.meta.revmap_file, 'a')
         b = branch or ''
-        f.write(str(revnum) + ' ' + node.hex(ha) + ' ' + b + '\n')
+        f.write(str(revnum) + ' ' + hex(ha) + ' ' + b + '\n')
         f.close()
         if revnum > self.meta.lastpulled or not self.meta.lastpulled:
             self.meta.lastpulled = revnum