Index: Objects/setobject.c =================================================================== --- Objects/setobject.c (revision 81048) +++ Objects/setobject.c (working copy) @@ -1476,9 +1476,25 @@ setentry *entry; Py_ssize_t pos = 0; - while (set_next((PySetObject *)other, &pos, &entry)) - if (set_discard_entry(so, entry) == -1) - return -1; + if (PySet_GET_SIZE(so) < PySet_GET_SIZE(other) ) { + while (set_next(so, &pos, &entry)) { + int rv = set_contains_entry((PySetObject *)other, entry); + if (rv == -1) + return -1; + if (rv == 1) { + PyObject *old_key; + old_key = entry->key; + Py_INCREF(dummy); + entry->key = dummy; + so->used--; + Py_DECREF(old_key); + } + } + } else { + while (set_next((PySetObject *)other, &pos, &entry)) + if (set_discard_entry(so, entry) == -1) + return -1; + } } else { PyObject *key, *it; it = PyObject_GetIter(other);