changeset 12948:de6a28ff5ffc

mq: use sets instead of lists for speed The code eventually converts data through sets to ensure unicity: do it earlier to allow faster __contains__ lookups and avoid `del l[l.index(x)]` kind of code.
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Sun, 07 Nov 2010 22:03:28 +0900
parents 4832717aed98
children f6b88f3bcc03
files hgext/mq.py
diffstat 1 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Sun Nov 07 18:59:27 2010 +0900
+++ b/hgext/mq.py	Sun Nov 07 22:03:28 2010 +0900
@@ -1289,6 +1289,9 @@
             else:
                 match = cmdutil.matchall(repo)
             m, a, r, d = repo.status(match=match)[:4]
+            mm = set(mm)
+            aa = set(aa)
+            dd = set(dd)
 
             # we might end up with files that were added between
             # qtip and the dirstate parent, but then changed in the
@@ -1296,31 +1299,31 @@
             # show up in the added section
             for x in m:
                 if x not in aa:
-                    mm.append(x)
+                    mm.add(x)
             # we might end up with files added by the local dirstate that
             # were deleted by the patch.  In this case, they should only
             # show up in the changed section.
             for x in a:
                 if x in dd:
-                    del dd[dd.index(x)]
-                    mm.append(x)
+                    dd.remove(x)
+                    mm.add(x)
                 else:
-                    aa.append(x)
+                    aa.add(x)
             # make sure any files deleted in the local dirstate
             # are not in the add or change column of the patch
             forget = []
             for x in d + r:
                 if x in aa:
-                    del aa[aa.index(x)]
+                    aa.remove(x)
                     forget.append(x)
                     continue
-                elif x in mm:
-                    del mm[mm.index(x)]
-                dd.append(x)
-
-            m = list(set(mm))
-            r = list(set(dd))
-            a = list(set(aa))
+                else:
+                    mm.discard(x)
+                dd.add(x)
+
+            m = list(mm)
+            r = list(dd)
+            a = list(aa)
             c = [filter(matchfn, l) for l in (m, a, r)]
             match = cmdutil.matchfiles(repo, set(c[0] + c[1] + c[2]))
             chunks = patch.diff(repo, patchparent, match=match,