Patchwork D7488: localrepo: introduce a `_quick_access_changeid` property

login
register
mail settings
Submitter phabricator
Date Nov. 24, 2019, 12:59 a.m.
Message ID <53763b2f4e7f448ea2f1c7e0980a27c1@localhost.localdomain>
Download mbox | patch
Permalink /patch/43503/
State Not Applicable
Headers show

Comments

phabricator - Nov. 24, 2019, 12:59 a.m.
Closed by commit rHG82ffb92092de: localrepo: introduce a `_quick_access_changeid` property (authored by marmoute).
This revision was automatically updated to reflect the committed changes.

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D7488?vs=18357&id=18374#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7488?vs=18357&id=18374

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7488/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7488

AFFECTED FILES
  mercurial/localrepo.py

CHANGE DETAILS




To: marmoute, #hg-reviewers, indygreg
Cc: mercurial-devel

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -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)