gh-131738: optimize builtin any/all/tuple calls with a generator expression arg (#131737)

This commit is contained in:
Irit Katriel 2025-03-28 10:35:20 +00:00 committed by GitHub
parent 674dbf3b3a
commit 2c8f329dc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 199 additions and 38 deletions

View file

@ -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;