diff options
author | Raymond Hettinger <python@rcn.com> | 2016-09-12 05:02:28 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-09-12 05:02:28 (GMT) |
commit | 4103e4dfbce8b6d9579565ab64868a721b01d2a1 (patch) | |
tree | 32b56d53517b38b8fd28cbdf8650886eab10d9c4 /Objects/setobject.c | |
parent | 34b74fffb32493b49b262ed9122d798d373477b7 (diff) | |
download | cpython-4103e4dfbce8b6d9579565ab64868a721b01d2a1.zip cpython-4103e4dfbce8b6d9579565ab64868a721b01d2a1.tar.gz cpython-4103e4dfbce8b6d9579565ab64868a721b01d2a1.tar.bz2 |
Issue #28071: Add early-out for differencing from an empty set.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r-- | Objects/setobject.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index 6dd403f..5846045 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -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); } |