From 2c8f329dc634290fb88636f85c05e473bc0104d5 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Fri, 28 Mar 2025 10:35:20 +0000 Subject: gh-131738: optimize builtin any/all/tuple calls with a generator expression arg (#131737) --- Python/pylifecycle.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 484583e1c79..934614e73b5 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -790,6 +790,26 @@ pycore_init_builtins(PyThreadState *tstate) } interp->callable_cache.len = len; + PyObject *all = PyDict_GetItemWithError(builtins_dict, &_Py_ID(all)); + if (!all) { + goto error; + } + + PyObject *any = PyDict_GetItemWithError(builtins_dict, &_Py_ID(any)); + if (!any) { + goto error; + } + + interp->common_consts[CONSTANT_ASSERTIONERROR] = PyExc_AssertionError; + interp->common_consts[CONSTANT_NOTIMPLEMENTEDERROR] = PyExc_NotImplementedError; + interp->common_consts[CONSTANT_BUILTIN_TUPLE] = (PyObject*)&PyTuple_Type; + interp->common_consts[CONSTANT_BUILTIN_ALL] = all; + interp->common_consts[CONSTANT_BUILTIN_ANY] = any; + + for (int i=0; i < NUM_COMMON_CONSTANTS; i++) { + assert(interp->common_consts[i] != NULL); + } + PyObject *list_append = _PyType_Lookup(&PyList_Type, &_Py_ID(append)); if (list_append == NULL) { goto error; -- cgit v1.2.3