]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43464: Optimize set.intersection() for non-set arguments (GH-31316)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 6 Apr 2022 16:56:28 +0000 (19:56 +0300)
committerGitHub <noreply@github.com>
Wed, 6 Apr 2022 16:56:28 +0000 (19:56 +0300)
Misc/NEWS.d/next/Core and Builtins/2022-02-13-21-53-29.bpo-43464.yupHjd.rst [new file with mode: 0644]
Objects/setobject.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-13-21-53-29.bpo-43464.yupHjd.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-13-21-53-29.bpo-43464.yupHjd.rst
new file mode 100644 (file)
index 0000000..a67ce7c
--- /dev/null
@@ -0,0 +1 @@
+Optimize :meth:`set.intersection` for non-set arguments.
index 022ae8e7f939229c9091fa5d3e9cc050871d86f0..18dc49be93d6dad10f1df51d9a3fdcc8dcdb70fc 100644 (file)
@@ -1240,6 +1240,10 @@ set_intersection(PySetObject *so, PyObject *other)
         if (rv) {
             if (set_add_entry(result, key, hash))
                 goto error;
+            if (PySet_GET_SIZE(result) >= PySet_GET_SIZE(so)) {
+                Py_DECREF(key);
+                break;
+            }
         }
         Py_DECREF(key);
     }