Skip to content

Commit 0909161

Browse files
committed
Create all constant lists in one or two ops.
1 parent 25e115e commit 0909161

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Python/peephole.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,25 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
321321
break;
322322

323323
/* Try to fold tuples of constants.
324+
Lists of constants are loaded as tuples and unpacked.
324325
Skip over BUILD_SEQN 1 UNPACK_SEQN 1.
325326
Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2.
326327
Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2. */
327328
case BUILD_TUPLE:
329+
case BUILD_LIST:
328330
j = get_arg(codestr, i);
331+
int islist = opcode == BUILD_LIST;
332+
if (islist && j <= 1) {
333+
break;
334+
}
329335
if (j > 0 && lastlc >= j) {
330336
h = lastn_const_start(codestr, op_start, j);
331337
if (ISBASICBLOCK(blocks, h, op_start)) {
332338
h = fold_tuple_on_constants(codestr, codelen,
333-
h, i+1, consts, j);
339+
h, i+1-islist, consts, j);
340+
if (h >= 0 && islist) {
341+
h = copy_op_arg(codestr, i, BUILD_LIST_UNPACK, 1, i+1);
342+
}
334343
break;
335344
}
336345
}

0 commit comments

Comments
 (0)