[Python-checkins] cpython: Issue #28071: Add early-out for differencing from an empty set.
raymond.hettinger
python-checkins at python.org
Mon Sep 12 01:02:35 EDT 2016
https://hg.python.org/cpython/rev/fa0af1a6344d
changeset: 103689:fa0af1a6344d
user: Raymond Hettinger <python at rcn.com>
date: Sun Sep 11 22:02:28 2016 -0700
summary:
Issue #28071: Add early-out for differencing from an empty set.
files:
Misc/NEWS | 2 ++
Objects/setobject.c | 8 ++++++++
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,8 @@
- 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)
diff --git a/Objects/setobject.c b/Objects/setobject.c
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1476,6 +1476,10 @@
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 @@
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);
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list