changeset 43765:e89e3275f658

localrepo: introduce a `_quick_access_changeid` property Having faster access to `null` is cuteā€¦ but limited. We want to speedup access to more useful revision, like `.`. We start with turning the fast path for `null` into something more generic. Differential Revision: https://phab.mercurial-scm.org/D7488
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 23 Nov 2019 16:52:44 -0800
parents f9068413bd0c
children d4c2221240a6
files mercurial/localrepo.py
diffstat 1 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Sun Nov 17 08:50:21 2019 +0100
+++ b/mercurial/localrepo.py	Sat Nov 23 16:52:44 2019 -0800
@@ -1514,6 +1514,19 @@
         narrowspec.save(self, newincludes, newexcludes)
         self.invalidate(clearfilecache=True)
 
+    @util.propertycache
+    def _quick_access_changeid(self):
+        """an helper dictionnary for __getitem__ calls
+
+        This contains a list of symbol we can recognise right away without
+        further processing.
+        """
+        return {
+            b'null': (nullrev, nullid),
+            nullrev: (nullrev, nullid),
+            nullid: (nullrev, nullid),
+        }
+
     def __getitem__(self, changeid):
         # dealing with special cases
         if changeid is None:
@@ -1531,8 +1544,10 @@
             ]
 
         # dealing with some special values
-        if changeid == b'null' or changeid == nullrev or changeid == nullid:
-            return context.changectx(self, nullrev, nullid, maybe_filtered=False)
+        quick_access = self._quick_access_changeid.get(changeid)
+        if quick_access is not None:
+            rev, node = quick_access
+            return context.changectx(self, rev, node, maybe_filtered=False)
         if changeid == b'tip':
             node = self.changelog.tip()
             rev = self.changelog.rev(node)