diff --git a/mercurial/context.py b/mercurial/context.py
index 3ef893520a85a881680b5128a7e0c399aaf2f6bb_bWVyY3VyaWFsL2NvbnRleHQucHk=..e9165c18f8dfd8a065f6c847c20b52befe3b5957_bWVyY3VyaWFsL2NvbnRleHQucHk= 100644
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -121,6 +121,7 @@
 
         modified, added, clean = [], [], []
         deleted, unknown, ignored = s[3], s[4], s[5]
+        deletedset = set(deleted)
         withflags = mf1.withflags() | mf2.withflags()
         for fn, mf2node in mf2.iteritems():
             if fn in mf1:
@@ -124,7 +125,7 @@
         withflags = mf1.withflags() | mf2.withflags()
         for fn, mf2node in mf2.iteritems():
             if fn in mf1:
-                if (fn not in deleted and
+                if (fn not in deletedset and
                     ((fn in withflags and mf1.flags(fn) != mf2.flags(fn)) or
                      (mf1[fn] != mf2node and
                       (mf2node or self[fn].cmp(other[fn]))))):
@@ -132,7 +133,7 @@
                 elif listclean:
                     clean.append(fn)
                 del mf1[fn]
-            elif fn not in deleted:
+            elif fn not in deletedset:
                 added.append(fn)
         removed = mf1.keys()
         if removed: