# HG changeset patch # User Matt Mackall # Date 1294787552 21600 # Node ID c2661863f16f35c00c81726a9d055e773246682e # Parent d1245ce817a80d97585fd62777835bcfd645bdd0 revlog: introduce a cache for partial lookups Partial lookups are always O(n), and often we look up the same one multiple times. diff -r d1245ce817a8 -r c2661863f16f mercurial/revlog.py --- a/mercurial/revlog.py Tue Jan 11 17:09:06 2011 -0600 +++ b/mercurial/revlog.py Tue Jan 11 17:12:32 2011 -0600 @@ -221,6 +221,7 @@ self.index = [] self._shallowroot = shallowroot self._parentdelta = 0 + self._pcache = {} v = REVLOG_DEFAULT_VERSION if hasattr(opener, 'options') and 'defversion' in opener.options: @@ -703,6 +704,9 @@ pass def _partialmatch(self, id): + if id in self._pcache: + return self._pcache[id] + if len(id) < 40: try: # hex(node)[:...] @@ -712,6 +716,7 @@ nl = [n for n in nl if hex(n).startswith(id)] if len(nl) > 0: if len(nl) == 1: + self._pcache[id] = nl[0] return nl[0] raise LookupError(id, self.indexfile, _('ambiguous identifier'))