aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2025-03-28 10:35:20 +0000
committerGitHub <noreply@github.com>2025-03-28 10:35:20 +0000
commit2c8f329dc634290fb88636f85c05e473bc0104d5 (patch)
treea16e7016315970312b8c61200d8f09573fc5f53b /Python/pylifecycle.c
parent674dbf3b3a72bd3d17298c2ead79f32edcff774a (diff)
downloadcpython-2c8f329dc634290fb88636f85c05e473bc0104d5.tar.gz
cpython-2c8f329dc634290fb88636f85c05e473bc0104d5.zip
gh-131738: optimize builtin any/all/tuple calls with a generator expression arg (#131737)
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c20
1 files changed, 20 insertions, 0 deletions
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;