optimize revlog.lookup when passed hex(node)[:...]
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Sun, 24 Sep 2006 13:52:27 +0200
changeset 3157 4fe41a9e4591
parent 3156 d01e4cb2f5f2
child 3158 ca00ce41a2e8
optimize revlog.lookup when passed hex(node)[:...] Instead of converting each node from the filenode to a hex form, convert the arg to a bin form. For a revlog with 26711 entries, doing 100 lookup: before: ~18s after : ~13s
mercurial/revlog.py
--- a/mercurial/revlog.py	Sun Sep 24 13:52:25 2006 +0200
+++ b/mercurial/revlog.py	Sun Sep 24 13:52:27 2006 +0200
@@ -763,15 +763,22 @@
             return self.node(rev)
         except (ValueError, OverflowError):
             pass
-        # hex(node)[:...]
-        node = None
-        for n in self.nodemap:
-            if hex(n).startswith(id):
-                if node is not None:
-                    raise RevlogError(_("Ambiguous identifier"))
-                node = n
-        if node is not None:
-            return node
+        try:
+            # hex(node)[:...]
+            if len(id) % 2 == 0:
+                bin_id = bin(id)
+            else:
+                bin_id = bin(id[:-1])
+            node = None
+            for n in self.nodemap:
+                if n.startswith(bin_id) and hex(n).startswith(id):
+                    if node is not None:
+                        raise RevlogError(_("Ambiguous identifier"))
+                    node = n
+            if node is not None:
+                return node
+        except TypeError:
+            pass
 
         # might need fixing if we change hash lengths
         if len(id) == 20 and id in self.nodemap: