summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorIvin Lee <62840497+rdrf2838@users.noreply.github.com>2023-08-05 04:10:46 (GMT)
committerGitHub <noreply@github.com>2023-08-05 04:10:46 (GMT)
commit4e6fac7fcc31fc6198fcddc612688b0a05ff7ae4 (patch)
treed701e62ffe0cfef764c25c8eb2dd84ea3ebf0a5d /Python
parent05a824f294f1409f33e32f1799d5b413dcf24445 (diff)
downloadcpython-4e6fac7fcc31fc6198fcddc612688b0a05ff7ae4.zip
cpython-4e6fac7fcc31fc6198fcddc612688b0a05ff7ae4.tar.gz
cpython-4e6fac7fcc31fc6198fcddc612688b0a05ff7ae4.tar.bz2
gh-106608: make uop trace variable length (#107531)
Executors are now more like tuples.
Diffstat (limited to 'Python')
-rw-r--r--Python/optimizer.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/Python/optimizer.c b/Python/optimizer.c
index 238ab02..d2ed8df 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -320,13 +320,7 @@ uop_name(int index) {
static Py_ssize_t
uop_len(_PyUOpExecutorObject *self)
{
- int count = 0;
- for (; count < _Py_UOP_MAX_TRACE_LENGTH; count++) {
- if (self->trace[count].opcode == 0) {
- break;
- }
- }
- return count;
+ return Py_SIZE(self);
}
static PyObject *
@@ -368,8 +362,8 @@ PySequenceMethods uop_as_sequence = {
static PyTypeObject UOpExecutor_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "uop_executor",
- .tp_basicsize = sizeof(_PyUOpExecutorObject),
- .tp_itemsize = 0,
+ .tp_basicsize = sizeof(_PyUOpExecutorObject) - sizeof(_PyUOpInstruction),
+ .tp_itemsize = sizeof(_PyUOpInstruction),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
.tp_dealloc = (destructor)uop_dealloc,
.tp_as_sequence = &uop_as_sequence,
@@ -699,15 +693,12 @@ uop_optimize(
return trace_length;
}
OBJECT_STAT_INC(optimization_traces_created);
- _PyUOpExecutorObject *executor = PyObject_New(_PyUOpExecutorObject, &UOpExecutor_Type);
+ _PyUOpExecutorObject *executor = PyObject_NewVar(_PyUOpExecutorObject, &UOpExecutor_Type, trace_length);
if (executor == NULL) {
return -1;
}
executor->base.execute = _PyUopExecute;
memcpy(executor->trace, trace, trace_length * sizeof(_PyUOpInstruction));
- if (trace_length < _Py_UOP_MAX_TRACE_LENGTH) {
- executor->trace[trace_length].opcode = 0; // Sentinel
- }
*exec_ptr = (_PyExecutorObject *)executor;
return 1;
}