mirror of
https://github.com/python/cpython.git
synced 2026-01-03 14:02:21 +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
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue