mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
bpo-47053: Reduce deoptimization in BINARY_OP_INPLACE_ADD_UNICODE (GH-31318)
* Don't deopt if refcounts are too big * Detect more at specialization time
This commit is contained in:
parent
d7163bb35d
commit
cca43b7d64
4 changed files with 11 additions and 7 deletions
|
@ -1742,7 +1742,7 @@ binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs)
|
|||
|
||||
void
|
||||
_Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
|
||||
int oparg)
|
||||
int oparg, PyObject **locals)
|
||||
{
|
||||
assert(_PyOpcode_Caches[BINARY_OP] == INLINE_CACHE_ENTRIES_BINARY_OP);
|
||||
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)(instr + 1);
|
||||
|
@ -1754,7 +1754,9 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
|
|||
}
|
||||
if (PyUnicode_CheckExact(lhs)) {
|
||||
_Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_BINARY_OP + 1];
|
||||
if (_Py_OPCODE(next) == STORE_FAST && Py_REFCNT(lhs) == 2) {
|
||||
bool to_store = (_Py_OPCODE(next) == STORE_FAST ||
|
||||
_Py_OPCODE(next) == STORE_FAST__LOAD_FAST);
|
||||
if (to_store && locals[_Py_OPARG(next)] == lhs) {
|
||||
_Py_SET_OPCODE(*instr, BINARY_OP_INPLACE_ADD_UNICODE);
|
||||
goto success;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue