D1257: dirstate: remove excess attribute lookups for dirstate.status (issue5714)

durham (Durham Goode) phabricator at mercurial-scm.org
Sat Oct 28 23:43:02 EDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGffeea2406276: dirstate: remove excess attribute lookups for dirstate.status (issue5714) (authored by durham, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1257?vs=3147&id=3150

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

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -1053,6 +1053,9 @@
         removed, deleted, clean = [], [], []
 
         dmap = self._map
+        dmap.preload()
+        dcontains = dmap.__contains__
+        dget = dmap.__getitem__
         ladd = lookup.append            # aka "unsure"
         madd = modified.append
         aadd = added.append
@@ -1074,7 +1077,7 @@
         full = listclean or match.traversedir is not None
         for fn, st in self.walk(match, subrepos, listunknown, listignored,
                                 full=full).iteritems():
-            if fn not in dmap:
+            if not dcontains(fn):
                 if (listignored or mexact(fn)) and dirignore(fn):
                     if listignored:
                         iadd(fn)
@@ -1089,7 +1092,7 @@
             # a list, but falls back to creating a full-fledged iterator in
             # general. That is much slower than simply accessing and storing the
             # tuple members one by one.
-            t = dmap[fn]
+            t = dget(fn)
             state = t[0]
             mode = t[1]
             size = t[2]
@@ -1216,8 +1219,8 @@
         return self.copymap
 
     def clear(self):
-        self._map = {}
-        self.copymap = {}
+        self._map.clear()
+        self.copymap.clear()
         self.setparents(nullid, nullid)
 
     def iteritems(self):
@@ -1247,6 +1250,10 @@
     def keys(self):
         return self._map.keys()
 
+    def preload(self):
+        """Loads the underlying data, if it's not already loaded"""
+        self._map
+
     def nonnormalentries(self):
         '''Compute the nonnormal dirstate entries from the dmap'''
         try:
@@ -1373,6 +1380,13 @@
         if not self._dirtyparents:
             self.setparents(*p)
 
+        # Avoid excess attribute lookups by fast pathing certain checks
+        self.__contains__ = self._map.__contains__
+        self.__getitem__ = self._map.__getitem__
+        self.__setitem__ = self._map.__setitem__
+        self.__delitem__ = self._map.__delitem__
+        self.get = self._map.get
+
     def write(self, st, now):
         st.write(parsers.pack_dirstate(self._map, self.copymap,
                                        self.parents(), now))



To: durham, #hg-reviewers, yuja
Cc: mercurial-devel


More information about the Mercurial-devel mailing list