mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
gh-90667: Add specializations of Py_DECREF when types are known (GH-30872)
This commit is contained in:
parent
ab0d35d70d
commit
da6c78584b
13 changed files with 147 additions and 85 deletions
|
@ -2511,7 +2511,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
|
|||
}
|
||||
if (PyFloat_CheckExact(item)) {
|
||||
f_result += PyFloat_AS_DOUBLE(item);
|
||||
Py_DECREF(item);
|
||||
_Py_DECREF_SPECIALIZED(item, _PyFloat_ExactDealloc);
|
||||
continue;
|
||||
}
|
||||
if (PyLong_Check(item)) {
|
||||
|
|
|
@ -1977,8 +1977,8 @@ handle_eval_breaker:
|
|||
STAT_INC(BINARY_OP, hit);
|
||||
PyObject *prod = _PyLong_Multiply((PyLongObject *)left, (PyLongObject *)right);
|
||||
SET_SECOND(prod);
|
||||
Py_DECREF(right);
|
||||
Py_DECREF(left);
|
||||
_Py_DECREF_SPECIALIZED(right, PyObject_Free);
|
||||
_Py_DECREF_SPECIALIZED(left, PyObject_Free);
|
||||
STACK_SHRINK(1);
|
||||
if (prod == NULL) {
|
||||
goto error;
|
||||
|
@ -1998,8 +1998,8 @@ handle_eval_breaker:
|
|||
((PyFloatObject *)right)->ob_fval;
|
||||
PyObject *prod = PyFloat_FromDouble(dprod);
|
||||
SET_SECOND(prod);
|
||||
Py_DECREF(right);
|
||||
Py_DECREF(left);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
|
||||
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
|
||||
STACK_SHRINK(1);
|
||||
if (prod == NULL) {
|
||||
goto error;
|
||||
|
@ -2017,8 +2017,8 @@ handle_eval_breaker:
|
|||
STAT_INC(BINARY_OP, hit);
|
||||
PyObject *sub = _PyLong_Subtract((PyLongObject *)left, (PyLongObject *)right);
|
||||
SET_SECOND(sub);
|
||||
Py_DECREF(right);
|
||||
Py_DECREF(left);
|
||||
_Py_DECREF_SPECIALIZED(right, PyObject_Free);
|
||||
_Py_DECREF_SPECIALIZED(left, PyObject_Free);
|
||||
STACK_SHRINK(1);
|
||||
if (sub == NULL) {
|
||||
goto error;
|
||||
|
@ -2037,8 +2037,8 @@ handle_eval_breaker:
|
|||
double dsub = ((PyFloatObject *)left)->ob_fval - ((PyFloatObject *)right)->ob_fval;
|
||||
PyObject *sub = PyFloat_FromDouble(dsub);
|
||||
SET_SECOND(sub);
|
||||
Py_DECREF(right);
|
||||
Py_DECREF(left);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
|
||||
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
|
||||
STACK_SHRINK(1);
|
||||
if (sub == NULL) {
|
||||
goto error;
|
||||
|
@ -2057,8 +2057,8 @@ handle_eval_breaker:
|
|||
PyObject *res = PyUnicode_Concat(left, right);
|
||||
STACK_SHRINK(1);
|
||||
SET_TOP(res);
|
||||
Py_DECREF(left);
|
||||
Py_DECREF(right);
|
||||
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
|
||||
if (TOP() == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -2090,10 +2090,10 @@ handle_eval_breaker:
|
|||
* that the string is safe to mutate.
|
||||
*/
|
||||
assert(Py_REFCNT(left) >= 2);
|
||||
Py_DECREF(left); // XXX never need to dealloc
|
||||
_Py_DECREF_NO_DEALLOC(left);
|
||||
STACK_SHRINK(2);
|
||||
PyUnicode_Append(target_local, right);
|
||||
Py_DECREF(right);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
|
||||
if (*target_local == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -2113,8 +2113,8 @@ handle_eval_breaker:
|
|||
((PyFloatObject *)right)->ob_fval;
|
||||
PyObject *sum = PyFloat_FromDouble(dsum);
|
||||
SET_SECOND(sum);
|
||||
Py_DECREF(right);
|
||||
Py_DECREF(left);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
|
||||
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
|
||||
STACK_SHRINK(1);
|
||||
if (sum == NULL) {
|
||||
goto error;
|
||||
|
@ -2132,8 +2132,8 @@ handle_eval_breaker:
|
|||
STAT_INC(BINARY_OP, hit);
|
||||
PyObject *sum = _PyLong_Add((PyLongObject *)left, (PyLongObject *)right);
|
||||
SET_SECOND(sum);
|
||||
Py_DECREF(right);
|
||||
Py_DECREF(left);
|
||||
_Py_DECREF_SPECIALIZED(right, PyObject_Free);
|
||||
_Py_DECREF_SPECIALIZED(left, PyObject_Free);
|
||||
STACK_SHRINK(1);
|
||||
if (sum == NULL) {
|
||||
goto error;
|
||||
|
@ -2192,7 +2192,7 @@ handle_eval_breaker:
|
|||
assert(res != NULL);
|
||||
Py_INCREF(res);
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(sub);
|
||||
_Py_DECREF_SPECIALIZED(sub, PyObject_Free);
|
||||
SET_TOP(res);
|
||||
Py_DECREF(list);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
|
||||
|
@ -2217,7 +2217,7 @@ handle_eval_breaker:
|
|||
assert(res != NULL);
|
||||
Py_INCREF(res);
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(sub);
|
||||
_Py_DECREF_SPECIALIZED(sub, PyObject_Free);
|
||||
SET_TOP(res);
|
||||
Py_DECREF(tuple);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
|
||||
|
@ -2359,7 +2359,7 @@ handle_eval_breaker:
|
|||
STACK_SHRINK(3);
|
||||
assert(old_value != NULL);
|
||||
Py_DECREF(old_value);
|
||||
Py_DECREF(sub);
|
||||
_Py_DECREF_SPECIALIZED(sub, PyObject_Free);
|
||||
Py_DECREF(list);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_STORE_SUBSCR);
|
||||
NOTRACE_DISPATCH();
|
||||
|
@ -3752,8 +3752,8 @@ handle_eval_breaker:
|
|||
JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
|
||||
NEXTOPARG();
|
||||
STACK_SHRINK(2);
|
||||
Py_DECREF(left);
|
||||
Py_DECREF(right);
|
||||
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
|
||||
assert(opcode == POP_JUMP_FORWARD_IF_FALSE ||
|
||||
opcode == POP_JUMP_BACKWARD_IF_FALSE ||
|
||||
opcode == POP_JUMP_FORWARD_IF_TRUE ||
|
||||
|
@ -3795,8 +3795,8 @@ handle_eval_breaker:
|
|||
JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
|
||||
NEXTOPARG();
|
||||
STACK_SHRINK(2);
|
||||
Py_DECREF(left);
|
||||
Py_DECREF(right);
|
||||
_Py_DECREF_SPECIALIZED(left, PyObject_Free);
|
||||
_Py_DECREF_SPECIALIZED(right, PyObject_Free);
|
||||
assert(opcode == POP_JUMP_FORWARD_IF_FALSE ||
|
||||
opcode == POP_JUMP_BACKWARD_IF_FALSE ||
|
||||
opcode == POP_JUMP_FORWARD_IF_TRUE ||
|
||||
|
@ -3841,8 +3841,8 @@ handle_eval_breaker:
|
|||
opcode == POP_JUMP_FORWARD_IF_TRUE ||
|
||||
opcode == POP_JUMP_BACKWARD_IF_TRUE);
|
||||
STACK_SHRINK(2);
|
||||
Py_DECREF(left);
|
||||
Py_DECREF(right);
|
||||
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
|
||||
assert(res == 0 || res == 1);
|
||||
int sign = 1 - res;
|
||||
int jump = (9 << (sign + 1)) & when_to_jump_mask;
|
||||
|
@ -4008,11 +4008,11 @@ handle_eval_breaker:
|
|||
PREDICTED(POP_JUMP_BACKWARD_IF_FALSE);
|
||||
PyObject *cond = POP();
|
||||
if (Py_IsTrue(cond)) {
|
||||
Py_DECREF(cond);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
DISPATCH();
|
||||
}
|
||||
if (Py_IsFalse(cond)) {
|
||||
Py_DECREF(cond);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
JUMPBY(-oparg);
|
||||
CHECK_EVAL_BREAKER();
|
||||
DISPATCH();
|
||||
|
@ -4034,10 +4034,10 @@ handle_eval_breaker:
|
|||
PREDICTED(POP_JUMP_FORWARD_IF_FALSE);
|
||||
PyObject *cond = POP();
|
||||
if (Py_IsTrue(cond)) {
|
||||
Py_DECREF(cond);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
}
|
||||
else if (Py_IsFalse(cond)) {
|
||||
Py_DECREF(cond);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
JUMPBY(oparg);
|
||||
}
|
||||
else {
|
||||
|
@ -4057,11 +4057,11 @@ handle_eval_breaker:
|
|||
TARGET(POP_JUMP_BACKWARD_IF_TRUE) {
|
||||
PyObject *cond = POP();
|
||||
if (Py_IsFalse(cond)) {
|
||||
Py_DECREF(cond);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
DISPATCH();
|
||||
}
|
||||
if (Py_IsTrue(cond)) {
|
||||
Py_DECREF(cond);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
JUMPBY(-oparg);
|
||||
CHECK_EVAL_BREAKER();
|
||||
DISPATCH();
|
||||
|
@ -4082,10 +4082,10 @@ handle_eval_breaker:
|
|||
TARGET(POP_JUMP_FORWARD_IF_TRUE) {
|
||||
PyObject *cond = POP();
|
||||
if (Py_IsFalse(cond)) {
|
||||
Py_DECREF(cond);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
}
|
||||
else if (Py_IsTrue(cond)) {
|
||||
Py_DECREF(cond);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
JUMPBY(oparg);
|
||||
}
|
||||
else {
|
||||
|
@ -4110,7 +4110,7 @@ handle_eval_breaker:
|
|||
CHECK_EVAL_BREAKER();
|
||||
DISPATCH();
|
||||
}
|
||||
Py_DECREF(value);
|
||||
_Py_DECREF_NO_DEALLOC(value);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -4126,21 +4126,25 @@ handle_eval_breaker:
|
|||
TARGET(POP_JUMP_BACKWARD_IF_NONE) {
|
||||
PyObject *value = POP();
|
||||
if (Py_IsNone(value)) {
|
||||
Py_DECREF(value);
|
||||
_Py_DECREF_NO_DEALLOC(value);
|
||||
JUMPBY(-oparg);
|
||||
CHECK_EVAL_BREAKER();
|
||||
DISPATCH();
|
||||
}
|
||||
Py_DECREF(value);
|
||||
else {
|
||||
Py_DECREF(value);
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(POP_JUMP_FORWARD_IF_NONE) {
|
||||
PyObject *value = POP();
|
||||
if (Py_IsNone(value)) {
|
||||
_Py_DECREF_NO_DEALLOC(value);
|
||||
JUMPBY(oparg);
|
||||
}
|
||||
Py_DECREF(value);
|
||||
else {
|
||||
Py_DECREF(value);
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -4149,7 +4153,7 @@ handle_eval_breaker:
|
|||
int err;
|
||||
if (Py_IsTrue(cond)) {
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(cond);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
DISPATCH();
|
||||
}
|
||||
if (Py_IsFalse(cond)) {
|
||||
|
@ -4173,7 +4177,7 @@ handle_eval_breaker:
|
|||
int err;
|
||||
if (Py_IsFalse(cond)) {
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(cond);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
DISPATCH();
|
||||
}
|
||||
if (Py_IsTrue(cond)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue