diff options
author | Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> | 2022-12-20 15:46:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-20 15:46:16 -0500 |
commit | c18d83118881333b9a0afd0add83afb2ba7300f7 (patch) | |
tree | 58bdb847e50dcd0ccff6e9e0ed3a5378e6e7f674 /Python/specialize.c | |
parent | 44892d45b038f919b0378590a776580a9d73b291 (diff) | |
download | cpython-git-c18d83118881333b9a0afd0add83afb2ba7300f7.tar.gz |
gh-100188: Reduce misses in BINARY_SUBSCR_(LIST/TUPLE)_INT (#100189)
Don't specialize if the index is negative.
Diffstat (limited to 'Python/specialize.c')
-rw-r--r-- | Python/specialize.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Python/specialize.c b/Python/specialize.c index a1666ccc91..c6c5027164 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -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); |