mirror of
https://github.com/python/cpython.git
synced 2024-11-24 10:24:35 +08:00
gh-100188: Reduce misses in BINARY_SUBSCR_(LIST/TUPLE)_INT (#100189)
Don't specialize if the index is negative.
This commit is contained in:
parent
44892d45b0
commit
c18d831188
@ -0,0 +1,3 @@
|
||||
The ``BINARY_SUBSCR_LIST_INT`` and ``BINARY_SUBSCR_TUPLE_INT``
|
||||
instructions are no longer used for negative integers because
|
||||
those instructions always miss when encountering negative integers.
|
@ -1302,8 +1302,12 @@ _Py_Specialize_BinarySubscr(
|
||||
PyTypeObject *container_type = Py_TYPE(container);
|
||||
if (container_type == &PyList_Type) {
|
||||
if (PyLong_CheckExact(sub)) {
|
||||
_py_set_opcode(instr, BINARY_SUBSCR_LIST_INT);
|
||||
goto success;
|
||||
if (Py_SIZE(sub) == 0 || Py_SIZE(sub) == 1) {
|
||||
_py_set_opcode(instr, BINARY_SUBSCR_LIST_INT);
|
||||
goto success;
|
||||
}
|
||||
SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OUT_OF_RANGE);
|
||||
goto fail;
|
||||
}
|
||||
SPECIALIZATION_FAIL(BINARY_SUBSCR,
|
||||
PySlice_Check(sub) ? SPEC_FAIL_SUBSCR_LIST_SLICE : SPEC_FAIL_OTHER);
|
||||
@ -1311,8 +1315,12 @@ _Py_Specialize_BinarySubscr(
|
||||
}
|
||||
if (container_type == &PyTuple_Type) {
|
||||
if (PyLong_CheckExact(sub)) {
|
||||
_py_set_opcode(instr, BINARY_SUBSCR_TUPLE_INT);
|
||||
goto success;
|
||||
if (Py_SIZE(sub) == 0 || Py_SIZE(sub) == 1) {
|
||||
_py_set_opcode(instr, BINARY_SUBSCR_TUPLE_INT);
|
||||
goto success;
|
||||
}
|
||||
SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OUT_OF_RANGE);
|
||||
goto fail;
|
||||
}
|
||||
SPECIALIZATION_FAIL(BINARY_SUBSCR,
|
||||
PySlice_Check(sub) ? SPEC_FAIL_SUBSCR_TUPLE_SLICE : SPEC_FAIL_OTHER);
|
||||
|
Loading…
Reference in New Issue
Block a user