@@ -320,13 +320,7 @@ uop_name(int index) {
320320static Py_ssize_t
321321uop_len (_PyUOpExecutorObject * self )
322322{
323- int count = 0 ;
324- for (; count < _Py_UOP_MAX_TRACE_LENGTH ; count ++ ) {
325- if (self -> trace [count ].opcode == 0 ) {
326- break ;
327- }
328- }
329- return count ;
323+ return Py_SIZE (self );
330324}
331325
332326static PyObject *
@@ -368,8 +362,8 @@ PySequenceMethods uop_as_sequence = {
368362static PyTypeObject UOpExecutor_Type = {
369363 PyVarObject_HEAD_INIT (& PyType_Type , 0 )
370364 .tp_name = "uop_executor" ,
371- .tp_basicsize = sizeof (_PyUOpExecutorObject ),
372- .tp_itemsize = 0 ,
365+ .tp_basicsize = sizeof (_PyUOpExecutorObject ) - sizeof ( _PyUOpInstruction ) ,
366+ .tp_itemsize = sizeof ( _PyUOpInstruction ) ,
373367 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION ,
374368 .tp_dealloc = (destructor )uop_dealloc ,
375369 .tp_as_sequence = & uop_as_sequence ,
@@ -699,15 +693,12 @@ uop_optimize(
699693 return trace_length ;
700694 }
701695 OBJECT_STAT_INC (optimization_traces_created );
702- _PyUOpExecutorObject * executor = PyObject_New (_PyUOpExecutorObject , & UOpExecutor_Type );
696+ _PyUOpExecutorObject * executor = PyObject_NewVar (_PyUOpExecutorObject , & UOpExecutor_Type , trace_length );
703697 if (executor == NULL ) {
704698 return -1 ;
705699 }
706700 executor -> base .execute = _PyUopExecute ;
707701 memcpy (executor -> trace , trace , trace_length * sizeof (_PyUOpInstruction ));
708- if (trace_length < _Py_UOP_MAX_TRACE_LENGTH ) {
709- executor -> trace [trace_length ].opcode = 0 ; // Sentinel
710- }
711702 * exec_ptr = (_PyExecutorObject * )executor ;
712703 return 1 ;
713704}
0 commit comments