bpo-47009: Let PRECALL_NO_KW_LIST_APPEND do its own POP_TOP (GH-32239) · python/cpython@6c6e040 (original) (raw)
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5040,15 +5040,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int | ||
5040 | 5040 | PyObject *list = SECOND(); |
5041 | 5041 | DEOPT_IF(!PyList_Check(list), PRECALL); |
5042 | 5042 | STAT_INC(PRECALL, hit); |
5043 | -SKIP_CALL(); | |
5043 | +// PRECALL + CALL + POP_TOP | |
5044 | +JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL + 1); | |
5045 | +assert(next_instr[-1] == POP_TOP); | |
5044 | 5046 | PyObject *arg = POP(); |
5045 | 5047 | if (_PyList_AppendTakeRef((PyListObject *)list, arg) < 0) { |
5046 | 5048 | goto error; |
5047 | 5049 | } |
5050 | +STACK_SHRINK(2); | |
5048 | 5051 | Py_DECREF(list); |
5049 | -STACK_SHRINK(1); | |
5050 | -Py_INCREF(Py_None); | |
5051 | -SET_TOP(Py_None); | |
5052 | 5052 | Py_DECREF(callable); |
5053 | 5053 | NOTRACE_DISPATCH(); |
5054 | 5054 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1435,7 +1435,10 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr, | ||
1435 | 1435 | } |
1436 | 1436 | PyInterpreterState *interp = _PyInterpreterState_GET(); |
1437 | 1437 | PyObject *list_append = interp->callable_cache.list_append; |
1438 | -if ((PyObject *)descr == list_append && oparg == 1) { | |
1438 | +_Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_PRECALL + 1 | |
1439 | ++ INLINE_CACHE_ENTRIES_CALL + 1]; | |
1440 | +bool pop = (_Py_OPCODE(next) == POP_TOP); | |
1441 | +if ((PyObject *)descr == list_append && oparg == 1 && pop) { | |
1439 | 1442 | _Py_SET_OPCODE(*instr, PRECALL_NO_KW_LIST_APPEND); |
1440 | 1443 | return 0; |
1441 | 1444 | } |