summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-03-17 18:20:54 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-03-17 18:20:54 +0000
commitb9d46b3942a9a8cce9cbca1e08f61ac23083a740 (patch)
tree5bdafa061ac9e470da57c37cb2f25356b2288104 /op.c
parent27d5b266d3ace9bd49a167d34f7350f3768d1326 (diff)
downloadperl-b9d46b3942a9a8cce9cbca1e08f61ac23083a740.tar.gz
Optimize away the assignment in the constructs C<my $s = undef>,
C<my @a = ()>, C<my %h = ()>. p4raw-id: //depot/perl@22520
Diffstat (limited to 'op.c')
-rw-r--r--op.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/op.c b/op.c
index b4d1ffc258..344130c452 100644
--- a/op.c
+++ b/op.c
@@ -3126,6 +3126,14 @@ Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
op_free(right);
return Nullop;
}
+ /* optimise C<my @x = ()> to C<my @x>, and likewise for hashes */
+ if ((left->op_type == OP_PADAV || left->op_type == OP_PADHV)
+ && right->op_type == OP_STUB
+ && (left->op_private & OPpLVAL_INTRO))
+ {
+ op_free(right);
+ return left;
+ }
curop = list(force_list(left));
o = newBINOP(OP_AASSIGN, flags, list(force_list(right)), curop);
o->op_private = (U8)(0 | (flags >> 8));
@@ -5593,6 +5601,19 @@ Perl_ck_sassign(pTHX_ OP *o)
return kid;
}
}
+ /* optimise C<my $x = undef> to C<my $x> */
+ if (kid->op_type == OP_UNDEF) {
+ OP *kkid = kid->op_sibling;
+ if (kkid && kkid->op_type == OP_PADSV
+ && (kkid->op_private & OPpLVAL_INTRO))
+ {
+ cLISTOPo->op_first = NULL;
+ kid->op_sibling = NULL;
+ op_free(o);
+ op_free(kid);
+ return kkid;
+ }
+ }
return o;
}