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
--- 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: