From: Serhiy Storchaka Date: Wed, 6 Apr 2022 16:56:28 +0000 (+0300) Subject: bpo-43464: Optimize set.intersection() for non-set arguments (GH-31316) X-Git-Tag: v3.11.0b1~444 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=31cd25f4e17cd68487dc76c1b2ec162a646818c2;p=thirdparty%2FPython%2Fcpython.git bpo-43464: Optimize set.intersection() for non-set arguments (GH-31316) --- 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 index 000000000000..a67ce7c9688e --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-13-21-53-29.bpo-43464.yupHjd.rst @@ -0,0 +1 @@ +Optimize :meth:`set.intersection` for non-set arguments. diff --git a/Objects/setobject.c b/Objects/setobject.c index 022ae8e7f939..18dc49be93d6 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -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); }