In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/5a8cd187c670a790aa65012a84cc1b7898b5ff02?hp=cf79272008437cd5f1b73b971b2bd97401f83ae8>

- Log -----------------------------------------------------------------
commit 5a8cd187c670a790aa65012a84cc1b7898b5ff02
Author: Father Chrysostomos <[email protected]>
Date:   Tue Nov 11 15:46:30 2014 -0800

    Don’t make temp copy for ()=...
    
    List assignment will make temporary copies if either side contains ops
    that *might* occur elsewhere on the stack.  That is obviously not nec-
    essary for ()=....
    
    ()= is often used to count the number of items, suppress void warn-
    ings, or force list context, so it’s worth optimising it.
    
    It’s actually possible to test this without examining the op tree.
    Just see whether we have redundant FETCH calls on items not assigned.
-----------------------------------------------------------------------

Summary of changes:
 op.c        | 8 ++++++++
 t/op/list.t | 9 ++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/op.c b/op.c
index 159296a..184f4ae 100644
--- a/op.c
+++ b/op.c
@@ -12786,6 +12786,14 @@ Perl_rpeep(pTHX_ OP *o)
            /* We do the common-vars check here, rather than in newASSIGNOP
               (as formerly), so that all lexical vars that get aliased are
               marked as such before we do the check.  */
+           /* There can’t be common vars if the lhs is a stub.  */
+           if (OP_SIBLING(cLISTOPx(cBINOPo->op_last)->op_first)
+                   == cLISTOPx(cBINOPo->op_last)->op_last
+            && cLISTOPx(cBINOPo->op_last)->op_last->op_type == OP_STUB)
+           {
+               o->op_private &=~ OPpASSIGN_COMMON;
+               break;
+           }
            if (o->op_private & OPpASSIGN_COMMON) {
                 /* See the comment before S_aassign_common_vars concerning
                    PL_generation sorcery.  */
diff --git a/t/op/list.t b/t/op/list.t
index 2802e62..d3f6b50 100644
--- a/t/op/list.t
+++ b/t/op/list.t
@@ -6,7 +6,7 @@ BEGIN {
 }
 
 require "./test.pl";
-plan( tests => 66 );
+plan( tests => 67 );
 
 @foo = (1, 2, 3, 4);
 cmp_ok($foo[0], '==', 1, 'first elem');
@@ -203,3 +203,10 @@ sub foo { () = ($a, my $b, ($c, do { while(1) {} })) }
     ($a,$b) = ($b = $foo."", $a = $bar . "");
     is("$a,$b", "foo,bar", 'common vars check accounts for OPpTARGET_MY');
 }
+
+sub TIESCALAR {bless{}}
+sub FETCH {$_[0]{fetched}++}
+sub empty {}
+tie $t, "";
+() = (empty(), ($t)x10); # empty() since sub calls usually result in copies
+is(tied($t)->{fetched}, undef, 'assignment to empty list makes no copies');

--
Perl5 Master Repository

Reply via email to