mirror of
https://github.com/python/cpython.git
synced 2025-10-27 16:57:08 +00:00
gh-131738: optimize builtin any/all/tuple calls with a generator expression arg (#131737)
This commit is contained in:
parent
674dbf3b3a
commit
2c8f329dc6
16 changed files with 199 additions and 38 deletions
|
|
@ -792,7 +792,9 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
|
|||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(aggregate_class));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(alias));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(align));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(all));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(allow_code));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(any));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(append));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(arg));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(argdefs));
|
||||
|
|
|
|||
|
|
@ -283,7 +283,9 @@ struct _Py_global_strings {
|
|||
STRUCT_FOR_ID(aggregate_class)
|
||||
STRUCT_FOR_ID(alias)
|
||||
STRUCT_FOR_ID(align)
|
||||
STRUCT_FOR_ID(all)
|
||||
STRUCT_FOR_ID(allow_code)
|
||||
STRUCT_FOR_ID(any)
|
||||
STRUCT_FOR_ID(append)
|
||||
STRUCT_FOR_ID(arg)
|
||||
STRUCT_FOR_ID(argdefs)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ extern "C" {
|
|||
|
||||
#include "pycore_ast_state.h" // struct ast_state
|
||||
#include "pycore_llist.h" // struct llist_node
|
||||
#include "pycore_opcode_utils.h" // NUM_COMMON_CONSTANTS
|
||||
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
|
||||
#include "pycore_structs.h" // PyHamtObject
|
||||
#include "pycore_tstate.h" // _PyThreadStateImpl
|
||||
|
|
@ -912,6 +913,7 @@ struct _is {
|
|||
struct ast_state ast;
|
||||
struct types_state types;
|
||||
struct callable_cache callable_cache;
|
||||
PyObject *common_consts[NUM_COMMON_CONSTANTS];
|
||||
bool jit;
|
||||
struct _PyExecutorObject *executor_list_head;
|
||||
size_t trace_run_counter;
|
||||
|
|
|
|||
|
|
@ -272,6 +272,7 @@ Known values:
|
|||
Python 3.14a6 3617 (Branch monitoring for async for loops)
|
||||
Python 3.14a6 3618 (Add oparg to END_ASYNC_FOR)
|
||||
Python 3.14a6 3619 (Renumber RESUME opcode from 149 to 128)
|
||||
Python 3.14a6 3620 (Optimize bytecode for all/any/tuple called on a genexp)
|
||||
|
||||
Python 3.15 will start with 3650
|
||||
|
||||
|
|
@ -284,7 +285,7 @@ PC/launcher.c must also be updated.
|
|||
|
||||
*/
|
||||
|
||||
#define PYC_MAGIC_NUMBER 3619
|
||||
#define PYC_MAGIC_NUMBER 3620
|
||||
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
|
||||
(little-endian) and then appending b'\r\n'. */
|
||||
#define PYC_MAGIC_NUMBER_TOKEN \
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ extern "C" {
|
|||
# error "this header requires Py_BUILD_CORE define"
|
||||
#endif
|
||||
|
||||
#include "opcode_ids.h"
|
||||
|
||||
#define MAX_REAL_OPCODE 254
|
||||
|
||||
#define IS_WITHIN_OPCODE_RANGE(opcode) \
|
||||
|
|
@ -67,7 +65,10 @@ extern "C" {
|
|||
/* Values used as the oparg for LOAD_COMMON_CONSTANT */
|
||||
#define CONSTANT_ASSERTIONERROR 0
|
||||
#define CONSTANT_NOTIMPLEMENTEDERROR 1
|
||||
#define NUM_COMMON_CONSTANTS 2
|
||||
#define CONSTANT_BUILTIN_TUPLE 2
|
||||
#define CONSTANT_BUILTIN_ALL 3
|
||||
#define CONSTANT_BUILTIN_ANY 4
|
||||
#define NUM_COMMON_CONSTANTS 5
|
||||
|
||||
/* Values used in the oparg for RESUME */
|
||||
#define RESUME_AT_FUNC_START 0
|
||||
|
|
|
|||
2
Include/internal/pycore_runtime_init_generated.h
generated
2
Include/internal/pycore_runtime_init_generated.h
generated
|
|
@ -790,7 +790,9 @@ extern "C" {
|
|||
INIT_ID(aggregate_class), \
|
||||
INIT_ID(alias), \
|
||||
INIT_ID(align), \
|
||||
INIT_ID(all), \
|
||||
INIT_ID(allow_code), \
|
||||
INIT_ID(any), \
|
||||
INIT_ID(append), \
|
||||
INIT_ID(arg), \
|
||||
INIT_ID(argdefs), \
|
||||
|
|
|
|||
|
|
@ -920,10 +920,18 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) {
|
|||
_PyUnicode_InternStatic(interp, &string);
|
||||
assert(_PyUnicode_CheckConsistency(string, 1));
|
||||
assert(PyUnicode_GET_LENGTH(string) != 1);
|
||||
string = &_Py_ID(all);
|
||||
_PyUnicode_InternStatic(interp, &string);
|
||||
assert(_PyUnicode_CheckConsistency(string, 1));
|
||||
assert(PyUnicode_GET_LENGTH(string) != 1);
|
||||
string = &_Py_ID(allow_code);
|
||||
_PyUnicode_InternStatic(interp, &string);
|
||||
assert(_PyUnicode_CheckConsistency(string, 1));
|
||||
assert(PyUnicode_GET_LENGTH(string) != 1);
|
||||
string = &_Py_ID(any);
|
||||
_PyUnicode_InternStatic(interp, &string);
|
||||
assert(_PyUnicode_CheckConsistency(string, 1));
|
||||
assert(PyUnicode_GET_LENGTH(string) != 1);
|
||||
string = &_Py_ID(append);
|
||||
_PyUnicode_InternStatic(interp, &string);
|
||||
assert(_PyUnicode_CheckConsistency(string, 1));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue