diff -r 178f9042af81 Objects/setobject.c --- a/Objects/setobject.c Sun Sep 23 11:11:07 2012 +0200 +++ b/Objects/setobject.c Mon Sep 24 11:22:37 2012 +0200 @@ -834,7 +834,7 @@ /* copy the itertor state */ tmp = *si; Py_XINCREF(tmp.si_set); - + /* iterate the temporary into a list */ for(;;) { PyObject *element = setiter_iternext(&tmp); @@ -1679,10 +1679,25 @@ static PyObject * set_isub(PySetObject *so, PyObject *other) { + int intersected = 0; + if (!PyAnySet_Check(other)) Py_RETURN_NOTIMPLEMENTED; + + // if small -= big , optimize. #issue8425 + if (PySet_GET_SIZE(other) > 8*PySet_GET_SIZE(so)) { + other = set_intersection(so, other); + if (other == NULL) + return NULL; + else + intersected = 1; + } + if (set_difference_update_internal(so, other) == -1) return NULL; + + if (intersected) + Py_DECREF(other); Py_INCREF(so); return (PyObject *)so; }