From 2ab07d2c47f5bb9325c7af98ce12654c3988cceb Mon Sep 17 00:00:00 2001 From: SimpleArt Date: Thu, 10 Feb 2022 18:53:37 -0500 Subject: [PATCH] Memory optimization for set.issubset Optimized `set.issubset` to use `O(min(len(self), len(set(other))))` memory instead of `O(len(set(other))) memory by using `self.intersection(other)` instead of `set(other)`. https://bugs.python.org/issue46705 --- Objects/setobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/setobject.c b/Objects/setobject.c index fe124945b1c7e0..4f4aa47545fdab 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1713,10 +1713,10 @@ set_issubset(PySetObject *so, PyObject *other) if (!PyAnySet_Check(other)) { PyObject *tmp, *result; - tmp = make_new_set(&PySet_Type, other); + tmp = set_intersection(so, other); if (tmp == NULL) return NULL; - result = set_issubset(so, tmp); + result = (PySet_GET_SIZE(so, tmp) == PySet_GET_SIZE(so)); Py_DECREF(tmp); return result; }