Skip to content

Commit 8157a84

Browse files
committed
Modernize UNPACK_SEQUENCE_LIST
1 parent 8affc82 commit 8157a84

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

Python/bytecodes.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ dummy_func(
863863
UNPACK_SEQUENCE,
864864
UNPACK_SEQUENCE_TWO_TUPLE,
865865
UNPACK_SEQUENCE_TUPLE,
866-
// UNPACK_SEQUENCE_LIST,
866+
UNPACK_SEQUENCE_LIST,
867867
};
868868

869869
inst(UNPACK_SEQUENCE, (unused/1, seq -- unused[oparg])) {
@@ -905,19 +905,15 @@ dummy_func(
905905
Py_DECREF(seq);
906906
}
907907

908-
// stack effect: (__0 -- __array[oparg])
909-
inst(UNPACK_SEQUENCE_LIST) {
910-
PyObject *seq = TOP();
908+
inst(UNPACK_SEQUENCE_LIST, (unused/1, seq -- values[oparg])) {
911909
DEOPT_IF(!PyList_CheckExact(seq), UNPACK_SEQUENCE);
912910
DEOPT_IF(PyList_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE);
913911
STAT_INC(UNPACK_SEQUENCE, hit);
914-
STACK_SHRINK(1);
915912
PyObject **items = _PyList_ITEMS(seq);
916-
while (oparg--) {
917-
PUSH(Py_NewRef(items[oparg]));
913+
for (int i = oparg; --i >= 0; ) {
914+
*values++ = Py_NewRef(items[i]);
918915
}
919916
Py_DECREF(seq);
920-
JUMPBY(INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE);
921917
}
922918

923919
inst(UNPACK_EX, (seq -- unused[oparg & 0xFF], unused, unused[oparg >> 8])) {

Python/generated_cases.c.h

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_metadata.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
127127
case UNPACK_SEQUENCE_TUPLE:
128128
return 1;
129129
case UNPACK_SEQUENCE_LIST:
130-
return -1;
130+
return 1;
131131
case UNPACK_EX:
132132
return 1;
133133
case STORE_ATTR:
@@ -473,7 +473,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
473473
case UNPACK_SEQUENCE_TUPLE:
474474
return oparg;
475475
case UNPACK_SEQUENCE_LIST:
476-
return -1;
476+
return oparg;
477477
case UNPACK_EX:
478478
return (oparg & 0xFF) + (oparg >> 8) + 1;
479479
case STORE_ATTR:
@@ -762,7 +762,7 @@ struct opcode_metadata {
762762
[UNPACK_SEQUENCE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC },
763763
[UNPACK_SEQUENCE_TWO_TUPLE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC },
764764
[UNPACK_SEQUENCE_TUPLE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC },
765-
[UNPACK_SEQUENCE_LIST] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
765+
[UNPACK_SEQUENCE_LIST] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC },
766766
[UNPACK_EX] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
767767
[STORE_ATTR] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
768768
[DELETE_ATTR] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },

0 commit comments

Comments
 (0)