This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Merge preinc and postinc
authorFather Chrysostomos <sprout@cpan.org>
Fri, 16 Sep 2011 23:10:57 +0000 (16:10 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 16 Sep 2011 23:14:23 +0000 (16:14 -0700)
They are almost identical.  This gives the compiler less code
to digest.

opcode.h
pp.c
pp_hot.c
pp_proto.h
regen/opcode.pl

index de1a42d..ce93bf3 100644 (file)
--- a/opcode.h
+++ b/opcode.h
@@ -22,7 +22,8 @@
 #define Perl_pp_chomp Perl_pp_chop
 #define Perl_pp_schomp Perl_pp_schop
 #define Perl_pp_i_preinc Perl_pp_preinc
-#define Perl_pp_i_predec Perl_pp_predec
+#define Perl_pp_predec Perl_pp_preinc
+#define Perl_pp_i_predec Perl_pp_preinc
 #define Perl_pp_i_postinc Perl_pp_postinc
 #define Perl_pp_i_postdec Perl_pp_postdec
 #define Perl_pp_slt Perl_pp_sle
@@ -967,8 +968,8 @@ EXT Perl_ppaddr_t PL_ppaddr[] /* or perlvars.h */
        Perl_pp_pos,
        Perl_pp_preinc,
        Perl_pp_i_preinc,       /* implemented by Perl_pp_preinc */
-       Perl_pp_predec,
-       Perl_pp_i_predec,       /* implemented by Perl_pp_predec */
+       Perl_pp_predec, /* implemented by Perl_pp_preinc */
+       Perl_pp_i_predec,       /* implemented by Perl_pp_preinc */
        Perl_pp_postinc,
        Perl_pp_i_postinc,      /* implemented by Perl_pp_postinc */
        Perl_pp_postdec,
diff --git a/pp.c b/pp.c
index ba07c31..59d318a 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -1051,23 +1051,6 @@ PP(pp_undef)
     RETPUSHUNDEF;
 }
 
-PP(pp_predec)
-{
-    dVAR; dSP;
-    if (SvTYPE(TOPs) >= SVt_PVAV || (isGV_with_GP(TOPs) && !SvFAKE(TOPs)))
-       Perl_croak_no_modify(aTHX);
-    if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)
-        && SvIVX(TOPs) != IV_MIN)
-    {
-       SvIV_set(TOPs, SvIVX(TOPs) - 1);
-       SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK);
-    }
-    else
-       sv_dec(TOPs);
-    SvSETMAGIC(TOPs);
-    return NORMAL;
-}
-
 PP(pp_postinc)
 {
     dVAR; dSP; dTARGET;
index 594d114..59fc443 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -362,16 +362,19 @@ PP(pp_eq)
 PP(pp_preinc)
 {
     dVAR; dSP;
+    const bool inc =
+       PL_op->op_type == OP_PREINC || PL_op->op_type == OP_I_PREINC;
     if (SvTYPE(TOPs) >= SVt_PVAV || (isGV_with_GP(TOPs) && !SvFAKE(TOPs)))
        Perl_croak_no_modify(aTHX);
     if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)
-        && SvIVX(TOPs) != IV_MAX)
+        && SvIVX(TOPs) != (inc ? IV_MAX : IV_MIN))
     {
-       SvIV_set(TOPs, SvIVX(TOPs) + 1);
+       SvIV_set(TOPs, SvIVX(TOPs) + (inc ? 1 : -1));
        SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK);
     }
     else /* Do all the PERL_PRESERVE_IVUV conditionals in sv_inc */
-       sv_inc(TOPs);
+       if (inc) sv_inc(TOPs);
+       else sv_dec(TOPs);
     SvSETMAGIC(TOPs);
     return NORMAL;
 }
index 5e19fc3..e795c8a 100644 (file)
@@ -170,7 +170,6 @@ PERL_CALLCONV OP *Perl_pp_pos(pTHX);
 PERL_CALLCONV OP *Perl_pp_postdec(pTHX);
 PERL_CALLCONV OP *Perl_pp_postinc(pTHX);
 PERL_CALLCONV OP *Perl_pp_pow(pTHX);
-PERL_CALLCONV OP *Perl_pp_predec(pTHX);
 PERL_CALLCONV OP *Perl_pp_preinc(pTHX);
 PERL_CALLCONV OP *Perl_pp_print(pTHX);
 PERL_CALLCONV OP *Perl_pp_prototype(pTHX);
index b4576da..5c81ec3 100755 (executable)
@@ -116,8 +116,7 @@ my @raw_alias = (
                 Perl_pp_chop => [qw(chop chomp)],
                 Perl_pp_schop => [qw(schop schomp)],
                 Perl_pp_bind => {connect => '#ifdef HAS_SOCKET'},
-                Perl_pp_preinc => ['i_preinc'],
-                Perl_pp_predec => ['i_predec'],
+                Perl_pp_preinc => ['i_preinc', 'predec', 'i_predec'],
                 Perl_pp_postinc => ['i_postinc'],
                 Perl_pp_postdec => ['i_postdec'],
                 Perl_pp_ehostent => [qw(enetent eprotoent eservent