Skip to content

Commit 3a09ea4

Browse files
committed
peep.c: optimise OP_LIST in scalar context
Note: This shouldn't occur particularly frequently, as superfluous arguments are likely to trigger warnings when scalar context is applied to the list. e.g. `my $x = (1,2,3);` is essentially the same as `my $x = 3;`
1 parent e95ec34 commit 3a09ea4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

peep.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,6 +3141,26 @@ Perl_rpeep(pTHX_ OP *o)
31413141
}
31423142
}
31433143

3144+
/* Given
3145+
list (in scalar context)
3146+
pushmark
3147+
something
3148+
The pushmark & list OPs are unnecessary.
3149+
*/
3150+
3151+
{
3152+
OP *nn = o->op_next->op_next;
3153+
if (OP_TYPE_IS(nn, OP_LIST) &&
3154+
((nn->op_flags & OPf_WANT) == OPf_WANT_SCALAR) ) {
3155+
if (oldop)
3156+
oldop->op_next = o->op_next;
3157+
o->op_next->op_next = nn->op_next;
3158+
op_null(nn);
3159+
op_null(o);
3160+
oldop = NULL; oldoldop = NULL;
3161+
}
3162+
}
3163+
31443164
/* Given
31453165
5 repeat/DOLIST
31463166
3 ex-list

0 commit comments

Comments
 (0)