remove unreachable code from various compare ops
authorDavid Mitchell <davem@iabyn.com>
Tue, 21 Jun 2011 13:40:12 +0000 (14:40 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sat, 25 Jun 2011 08:28:17 +0000 (09:28 +0100)
All the compare ops (such as pp_le), have an initial:

    tryAMAGICbin_MG(le_amg, AMGf_numeric);

The effect of the AMGf_numeric flag is that, if the le overloading fails,
but either of the args on the stack is a reference, then that arg is
replaced with a temporary non-ref arg that is either the result of
'0+' overloading, or is a UV with the numerical value of the ref's
address.  So by the time the main body of the op is called, neither arg
can be a ref.

Thus a whole bunch of nearly identical blocks can be removed, which *used*
to handle comparing refs:

    if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
        SP--;
        SETs(boolSV(SvRV(TOPs) <= SvRV(TOPp1s)));
        RETURN;
    }

pp.c
pp_hot.c

diff --git a/pp.c b/pp.c
index f815d0a..2cbbfdd 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -2059,16 +2059,6 @@ PP(pp_lt)
        }
     }
 #endif
-#ifndef NV_PRESERVES_UV
-#ifdef PERL_PRESERVE_IVUV
-    else
-#endif
-    if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
-       SP--;
-       SETs(boolSV(SvRV(TOPs) < SvRV(TOPp1s)));
-       RETURN;
-    }
-#endif
     {
 #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
       dPOPTOPnnrl_nomg;
@@ -2143,16 +2133,6 @@ PP(pp_gt)
        }
     }
 #endif
-#ifndef NV_PRESERVES_UV
-#ifdef PERL_PRESERVE_IVUV
-    else
-#endif
-    if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
-        SP--;
-        SETs(boolSV(SvRV(TOPs) > SvRV(TOPp1s)));
-        RETURN;
-    }
-#endif
     {
 #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
       dPOPTOPnnrl_nomg;
@@ -2227,16 +2207,6 @@ PP(pp_le)
        }
     }
 #endif
-#ifndef NV_PRESERVES_UV
-#ifdef PERL_PRESERVE_IVUV
-    else
-#endif
-    if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
-        SP--;
-        SETs(boolSV(SvRV(TOPs) <= SvRV(TOPp1s)));
-        RETURN;
-    }
-#endif
     {
 #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
       dPOPTOPnnrl_nomg;
@@ -2311,16 +2281,6 @@ PP(pp_ge)
        }
     }
 #endif
-#ifndef NV_PRESERVES_UV
-#ifdef PERL_PRESERVE_IVUV
-    else
-#endif
-    if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
-        SP--;
-        SETs(boolSV(SvRV(TOPs) >= SvRV(TOPp1s)));
-        RETURN;
-    }
-#endif
     {
 #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
       dPOPTOPnnrl_nomg;
@@ -2339,13 +2299,6 @@ PP(pp_ne)
 {
     dVAR; dSP;
     tryAMAGICbin_MG(ne_amg,AMGf_set|AMGf_numeric);
-#ifndef NV_PRESERVES_UV
-    if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
-        SP--;
-       SETs(boolSV(SvRV(TOPs) != SvRV(TOPp1s)));
-       RETURN;
-    }
-#endif
 #ifdef PERL_PRESERVE_IVUV
     SvIV_please_nomg(TOPs);
     if (SvIOK(TOPs)) {
@@ -2416,14 +2369,6 @@ PP(pp_ncmp)
 {
     dVAR; dSP; dTARGET;
     tryAMAGICbin_MG(ncmp_amg, AMGf_numeric);
-#ifndef NV_PRESERVES_UV
-    if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
-       const UV right = PTR2UV(SvRV(POPs));
-       const UV left = PTR2UV(SvRV(TOPs));
-       SETi((left > right) - (left < right));
-       RETURN;
-    }
-#endif
 #ifdef PERL_PRESERVE_IVUV
     /* Fortunately it seems NaN isn't IOK */
     SvIV_please_nomg(TOPs);
index d2e5240..c284781 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -342,13 +342,6 @@ PP(pp_eq)
 {
     dVAR; dSP;
     tryAMAGICbin_MG(eq_amg, AMGf_set|AMGf_numeric);
-#ifndef NV_PRESERVES_UV
-    if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
-        SP--;
-       SETs(boolSV(SvRV(TOPs) == SvRV(TOPp1s)));
-       RETURN;
-    }
-#endif
 #ifdef PERL_PRESERVE_IVUV
     SvIV_please_nomg(TOPs);
     if (SvIOK(TOPs)) {