localrepo: optimize internode status calls using withflags
authorJesse Glick <jesse.glick@oracle.com>
Fri, 04 May 2012 15:56:45 -0400
changeset 16646 a1dcd842ce17
parent 16645 9a21fc2c7d32
child 16647 14913fcb30c6
localrepo: optimize internode status calls using withflags Introduce manifestdict.withflags() to get a set of all files which have any flags set, since these are likely to be a minority. Otherwise checking .flags() for every file is a lot of dictionary lookups and is quite slow.
mercurial/localrepo.py
mercurial/manifest.py
--- a/mercurial/localrepo.py	Fri May 04 15:54:55 2012 -0400
+++ b/mercurial/localrepo.py	Fri May 04 15:56:45 2012 -0400
@@ -1420,10 +1420,11 @@
                 mf2 = mfmatches(ctx2)
 
             modified, added, clean = [], [], []
+            withflags = mf1.withflags() | mf2.withflags()
             for fn in mf2:
                 if fn in mf1:
                     if (fn not in deleted and
-                        (mf1.flags(fn) != mf2.flags(fn) or
+                        ((fn in withflags and mf1.flags(fn) != mf2.flags(fn)) or
                          (mf1[fn] != mf2[fn] and
                           (mf2[fn] or ctx1[fn].cmp(ctx2[fn]))))):
                         modified.append(fn)
--- a/mercurial/manifest.py	Fri May 04 15:54:55 2012 -0400
+++ b/mercurial/manifest.py	Fri May 04 15:56:45 2012 -0400
@@ -19,6 +19,8 @@
         self._flags = flags
     def flags(self, f):
         return self._flags.get(f, "")
+    def withflags(self):
+        return set(self._flags.keys())
     def set(self, f, flags):
         self._flags[f] = flags
     def copy(self):