mirror of
https://github.com/python/cpython.git
synced 2026-01-20 14:20:27 +00:00
gh-134584: Eliminate redundant refcounting from _CONTAINS_{OP|OP_SET|OP_DICT} (GH-143731)
Signed-off-by: Manjusaka <me@manjusaka.me>
This commit is contained in:
parent
c315748060
commit
e535bdb0a2
10 changed files with 253 additions and 130 deletions
|
|
@ -2855,14 +2855,18 @@ dummy_func(
|
|||
CONTAINS_OP_DICT,
|
||||
};
|
||||
|
||||
op(_CONTAINS_OP, (left, right -- b)) {
|
||||
op(_CONTAINS_OP, (left, right -- b, l, r)) {
|
||||
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
|
||||
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
|
||||
|
||||
int res = PySequence_Contains(right_o, left_o);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res < 0);
|
||||
if (res < 0) {
|
||||
ERROR_NO_POP();
|
||||
}
|
||||
b = (res ^ oparg) ? PyStackRef_True : PyStackRef_False;
|
||||
l = left;
|
||||
r = right;
|
||||
INPUTS_DEAD();
|
||||
}
|
||||
|
||||
specializing op(_SPECIALIZE_CONTAINS_OP, (counter/1, left, right -- left, right)) {
|
||||
|
|
@ -2877,16 +2881,16 @@ dummy_func(
|
|||
#endif /* ENABLE_SPECIALIZATION_FT */
|
||||
}
|
||||
|
||||
macro(CONTAINS_OP) = _SPECIALIZE_CONTAINS_OP + _CONTAINS_OP;
|
||||
macro(CONTAINS_OP) = _SPECIALIZE_CONTAINS_OP + _CONTAINS_OP + POP_TOP + POP_TOP;
|
||||
|
||||
op(_GUARD_TOS_ANY_SET, (tos -- tos)) {
|
||||
PyObject *o = PyStackRef_AsPyObjectBorrow(tos);
|
||||
DEOPT_IF(!PyAnySet_CheckExact(o));
|
||||
}
|
||||
|
||||
macro(CONTAINS_OP_SET) = _GUARD_TOS_ANY_SET + unused/1 + _CONTAINS_OP_SET;
|
||||
macro(CONTAINS_OP_SET) = _GUARD_TOS_ANY_SET + unused/1 + _CONTAINS_OP_SET + POP_TOP + POP_TOP;
|
||||
|
||||
op(_CONTAINS_OP_SET, (left, right -- b)) {
|
||||
op(_CONTAINS_OP_SET, (left, right -- b, l, r)) {
|
||||
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
|
||||
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
|
||||
|
||||
|
|
@ -2894,23 +2898,31 @@ dummy_func(
|
|||
STAT_INC(CONTAINS_OP, hit);
|
||||
// Note: both set and frozenset use the same seq_contains method!
|
||||
int res = _PySet_Contains((PySetObject *)right_o, left_o);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res < 0);
|
||||
if (res < 0) {
|
||||
ERROR_NO_POP();
|
||||
}
|
||||
b = (res ^ oparg) ? PyStackRef_True : PyStackRef_False;
|
||||
l = left;
|
||||
r = right;
|
||||
INPUTS_DEAD();
|
||||
}
|
||||
|
||||
macro(CONTAINS_OP_DICT) = _GUARD_TOS_DICT + unused/1 + _CONTAINS_OP_DICT;
|
||||
macro(CONTAINS_OP_DICT) = _GUARD_TOS_DICT + unused/1 + _CONTAINS_OP_DICT + POP_TOP + POP_TOP;
|
||||
|
||||
op(_CONTAINS_OP_DICT, (left, right -- b)) {
|
||||
op(_CONTAINS_OP_DICT, (left, right -- b, l, r)) {
|
||||
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
|
||||
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
|
||||
|
||||
assert(PyDict_CheckExact(right_o));
|
||||
STAT_INC(CONTAINS_OP, hit);
|
||||
int res = PyDict_Contains(right_o, left_o);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res < 0);
|
||||
if (res < 0) {
|
||||
ERROR_NO_POP();
|
||||
}
|
||||
b = (res ^ oparg) ? PyStackRef_True : PyStackRef_False;
|
||||
l = left;
|
||||
r = right;
|
||||
INPUTS_DEAD();
|
||||
}
|
||||
|
||||
inst(CHECK_EG_MATCH, (exc_value_st, match_type_st -- rest, match)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue