add Deparse/Concise support for inplace sort (change 22349)
authorDave Mitchell <davem@fdisolutions.com>
Fri, 20 Feb 2004 15:34:27 +0000 (15:34 +0000)
committerDave Mitchell <davem@fdisolutions.com>
Fri, 20 Feb 2004 15:34:27 +0000 (15:34 +0000)
p4raw-id: //depot/perl@22350

ext/B/B/Concise.pm
ext/B/B/Deparse.pm

index 2b8a612..5c5fd5d 100644 (file)
@@ -416,7 +416,7 @@ $priv{"exists"}{64} = "SUB";
 $priv{$_}{64} = "LOCALE"
   for ("sort", "prtf", "sprintf", "slt", "sle", "seq", "sne", "sgt", "sge",
        "scmp", "lc", "uc", "lcfirst", "ucfirst");
-@{$priv{"sort"}}{1,2,4} = ("NUM", "INT", "REV");
+@{$priv{"sort"}}{1,2,4,8} = ("NUM", "INT", "REV", "INPLACE");
 $priv{"threadsv"}{64} = "SVREFd";
 @{$priv{$_}}{16,32,64,128} = ("INBIN","INCR","OUTBIN","OUTCR")
   for ("open", "backtick");
index 21a3379..65f314d 100644 (file)
@@ -14,7 +14,7 @@ use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
         OPpLVAL_INTRO OPpOUR_INTRO OPpENTERSUB_AMPER OPpSLICE OPpCONST_BARE
         OPpTRANS_SQUASH OPpTRANS_DELETE OPpTRANS_COMPLEMENT OPpTARGET_MY
         OPpCONST_ARYBASE OPpEXISTS_SUB OPpSORT_NUMERIC OPpSORT_INTEGER
-        OPpSORT_REVERSE
+        OPpSORT_REVERSE OPpSORT_INPLACE
         SVf_IOK SVf_NOK SVf_ROK SVf_POK SVpad_OUR SVf_FAKE SVs_RMG SVs_SMG
          CVf_METHOD CVf_LOCKED CVf_LVALUE CVf_ASSERTION
         PMf_KEEP PMf_GLOBAL PMf_CONTINUE PMf_EVAL PMf_ONCE PMf_SKIPWHITE
@@ -2311,6 +2311,10 @@ sub indirop {
        $expr = $self->deparse($kid, 6);
        push @exprs, $expr;
     }
+    if ($name eq "sort" && ($op->private & OPpSORT_INPLACE)) {
+       return "$exprs[0] = sort $indir $exprs[0]";
+    }
+
     my $args = $indir . join(", ", @exprs);
     if ($indir ne "" and $name eq "sort") {
        # We don't want to say "sort(f 1, 2, 3)", since perl -w will