mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00: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:
parent
c3febba73b
commit
713684de53
10 changed files with 1232 additions and 940 deletions
18
Python/optimizer_cases.c.h
generated
18
Python/optimizer_cases.c.h
generated
|
|
@ -799,6 +799,24 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS: {
|
||||
JitOptRef sub_st;
|
||||
JitOptRef tuple_st;
|
||||
sub_st = stack_pointer[-1];
|
||||
tuple_st = stack_pointer[-2];
|
||||
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);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case _BINARY_OP_SUBSCR_TUPLE_INT: {
|
||||
JitOptRef sub_st;
|
||||
JitOptRef tuple_st;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue