Mercurial > hg-stable
changeset 13258:c2661863f16f
revlog: introduce a cache for partial lookups
Partial lookups are always O(n), and often we look up the same
one multiple times.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 11 Jan 2011 17:12:32 -0600 |
parents | d1245ce817a8 |
children | 3b616dfa4b17 |
files | mercurial/revlog.py |
diffstat | 1 files changed, 5 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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'))