mirror of
https://github.com/python/cpython.git
synced 2026-05-06 12:49:07 -04:00
gh-131798: Remove bounds check when indexing into tuples with a constant index (#137607)
* Remove bounds check when indexing into tuples with a constant index * Add news entry * fixup after rebase
This commit is contained in:
@@ -332,6 +332,19 @@ dummy_func(void) {
|
||||
i = sub_st;
|
||||
}
|
||||
|
||||
op(_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS, (tuple_st, sub_st -- tuple_st, sub_st)) {
|
||||
assert(sym_matches_type(tuple_st, &PyTuple_Type));
|
||||
if (sym_is_const(ctx, sub_st)) {
|
||||
assert(PyLong_CheckExact(sym_get_const(ctx, sub_st)));
|
||||
long index = PyLong_AsLong(sym_get_const(ctx, sub_st));
|
||||
assert(index >= 0);
|
||||
int tuple_length = sym_tuple_length(tuple_st);
|
||||
if (tuple_length != -1 && index < tuple_length) {
|
||||
REPLACE_OP(this_instr, _NOP, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
op(_BINARY_OP_SUBSCR_TUPLE_INT, (tuple_st, sub_st -- res, ts, ss)) {
|
||||
assert(sym_matches_type(tuple_st, &PyTuple_Type));
|
||||
if (sym_is_const(ctx, sub_st)) {
|
||||
|
||||
Reference in New Issue
Block a user