Skip to content

Commit c8ceedf

Browse files
committed
process 2 instructions per iteration
1 parent f357994 commit c8ceedf

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

Python/flowgraph.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,8 +1482,6 @@ fold_constant_intrinsic_list_to_tuple(basicblock *bb, int i,
14821482
return ERROR;
14831483
}
14841484

1485-
bool expect_append = true;
1486-
14871485
for (int pos = i-1; pos >= 0; pos--) {
14881486
cfg_instr *instr = &bb->b_instr[pos];
14891487

@@ -1492,10 +1490,6 @@ fold_constant_intrinsic_list_to_tuple(basicblock *bb, int i,
14921490
}
14931491

14941492
if (instr->i_opcode == BUILD_LIST && instr->i_oparg == 0) {
1495-
if (!expect_append) {
1496-
/* Not a sequence start */
1497-
goto exit;
1498-
}
14991493
/* Sequence start, we are done. */
15001494
if (PyList_Reverse(list) < 0) {
15011495
goto error;
@@ -1510,27 +1504,30 @@ fold_constant_intrinsic_list_to_tuple(basicblock *bb, int i,
15101504
return instr_make_load_const(intrinsic, newconst, consts, const_cache);
15111505
}
15121506

1513-
if (expect_append) {
1514-
if (!(instr->i_opcode == LIST_APPEND && instr->i_oparg == 1)) {
1515-
goto exit;
1516-
}
1507+
if (pos < 1) {
1508+
/* Can't process 2 instructions. */
1509+
goto exit;
15171510
}
1518-
else {
1519-
if (!loads_const(instr->i_opcode)) {
1520-
goto exit;
1521-
}
1522-
PyObject *constant = get_const_value(instr->i_opcode, instr->i_oparg, consts);
1523-
if (constant == NULL) {
1524-
goto error;
1525-
}
1526-
int r = PyList_Append(list, constant);
1527-
Py_DECREF(constant);
1528-
if (r < 0) {
1529-
goto error;
1530-
}
1511+
1512+
if (!(instr->i_opcode == LIST_APPEND && instr->i_oparg == 1)) {
1513+
goto exit;
15311514
}
15321515

1533-
expect_append = !expect_append;
1516+
instr = &bb->b_instr[--pos];
1517+
if (!loads_const(instr->i_opcode)) {
1518+
goto exit;
1519+
}
1520+
1521+
PyObject *constant = get_const_value(instr->i_opcode, instr->i_oparg, consts);
1522+
if (constant == NULL) {
1523+
goto error;
1524+
}
1525+
1526+
int r = PyList_Append(list, constant);
1527+
Py_DECREF(constant);
1528+
if (r < 0) {
1529+
goto error;
1530+
}
15341531
}
15351532

15361533
exit:
@@ -2388,7 +2385,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
23882385
INSTR_SET_OP0(inst, NOP);
23892386
}
23902387
else {
2391-
fold_constant_intrinsic_list_to_tuple(bb, i, consts, const_cache);
2388+
RETURN_IF_ERROR(fold_constant_intrinsic_list_to_tuple(bb, i, consts, const_cache));
23922389
}
23932390
}
23942391
else if (oparg == INTRINSIC_UNARY_POSITIVE) {

0 commit comments

Comments
 (0)