]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #28071: Add early-out for differencing from an empty set.
authorRaymond Hettinger <python@rcn.com>
Mon, 12 Sep 2016 05:02:28 +0000 (22:02 -0700)
committerRaymond Hettinger <python@rcn.com>
Mon, 12 Sep 2016 05:02:28 +0000 (22:02 -0700)
Misc/NEWS
Objects/setobject.c

index 1c253b6366e0954c64ff0b940312099a224820cd..083b33f7dd5e7d28c1dfcfd5b6a67dd814b590bf 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,8 @@ Core and Builtins
 
 - Issue #28046: Remove platform-specific directories from sys.path.
 
+- Issue #28071: Add early-out for differencing from an empty set.
+
 - Issue #25758: Prevents zipimport from unnecessarily encoding a filename
   (patch by Eryk Sun)
 
index 6dd403f30fa364dfad2a977c1510b03d9544dca0..5846045376d64396bca2ba1bd4033f90a4d05e13 100644 (file)
@@ -1476,6 +1476,10 @@ PyDoc_STRVAR(isdisjoint_doc,
 static int
 set_difference_update_internal(PySetObject *so, PyObject *other)
 {
+    if (PySet_GET_SIZE(so) == 0) {
+        return 0;
+    }
+
     if ((PyObject *)so == other)
         return set_clear_internal(so);
 
@@ -1550,6 +1554,10 @@ set_difference(PySetObject *so, PyObject *other)
     Py_ssize_t pos = 0;
     int rv;
 
+    if (PySet_GET_SIZE(so) == 0) {
+        return set_copy(so);
+    }
+
     if (!PyAnySet_Check(other)  && !PyDict_CheckExact(other)) {
         return set_copy_and_difference(so, other);
     }