From 17058fe0299db92774e157ee0067d1b500324e4f Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 16 Sep 2011 16:10:57 -0700 Subject: [PATCH] Merge preinc and postinc They are almost identical. This gives the compiler less code to digest. --- opcode.h | 7 ++++--- pp.c | 17 ----------------- pp_hot.c | 9 ++++++--- pp_proto.h | 1 - regen/opcode.pl | 3 +-- 5 files changed, 11 insertions(+), 26 deletions(-) diff --git a/opcode.h b/opcode.h index de1a42d..ce93bf3 100644 --- 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 --- 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; diff --git a/pp_hot.c b/pp_hot.c index 594d114..59fc443 100644 --- 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; } diff --git a/pp_proto.h b/pp_proto.h index 5e19fc3..e795c8a 100644 --- a/pp_proto.h +++ b/pp_proto.h @@ -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); diff --git a/regen/opcode.pl b/regen/opcode.pl index b4576da..5c81ec3 100755 --- a/regen/opcode.pl +++ b/regen/opcode.pl @@ -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 -- 1.8.3.1