Merge pp_slt, pp_sgt and pp_sge into pp_sle. (The most commonly used
Nicholas Clark [Mon, 7 Nov 2005 21:31:16 +0000 (21:31 +0000)]
of the 4. Not that any are that popular.)

p4raw-id: //depot/perl@26039

mathoms.c
opcode.h
opcode.pl
pp.c

index c0fc740..113aac0 100644 (file)
--- a/mathoms.c
+++ b/mathoms.c
@@ -1020,6 +1020,21 @@ PP(pp_lcfirst)
     return pp_ucfirst();
 }
 
+PP(pp_slt)
+{
+    return pp_sle();
+}
+
+PP(pp_sgt)
+{
+    return pp_sle();
+}
+
+PP(pp_sge)
+{
+    return pp_sle();
+}
+
 U8 *
 Perl_uvuni_to_utf8(pTHX_ U8 *d, UV uv)
 {
index 0086001..7cd088e 100644 (file)
--- a/opcode.h
+++ b/opcode.h
@@ -850,10 +850,10 @@ EXT Perl_ppaddr_t PL_ppaddr[] /* or perlvars.h */
        MEMBER_TO_FPTR(Perl_pp_i_ne),
        MEMBER_TO_FPTR(Perl_pp_ncmp),
        MEMBER_TO_FPTR(Perl_pp_i_ncmp),
-       MEMBER_TO_FPTR(Perl_pp_slt),
-       MEMBER_TO_FPTR(Perl_pp_sgt),
+       MEMBER_TO_FPTR(Perl_pp_sle),    /* Perl_pp_slt */
+       MEMBER_TO_FPTR(Perl_pp_sle),    /* Perl_pp_sgt */
        MEMBER_TO_FPTR(Perl_pp_sle),
-       MEMBER_TO_FPTR(Perl_pp_sge),
+       MEMBER_TO_FPTR(Perl_pp_sle),    /* Perl_pp_sge */
        MEMBER_TO_FPTR(Perl_pp_seq),
        MEMBER_TO_FPTR(Perl_pp_sne),
        MEMBER_TO_FPTR(Perl_pp_scmp),
index 0c1026d..ae7ee66 100755 (executable)
--- a/opcode.pl
+++ b/opcode.pl
@@ -77,6 +77,7 @@ my @raw_alias = (
                  Perl_pp_and => ['andassign'],
                 Perl_pp_or => ['orassign'],
                 Perl_pp_ucfirst => ['lcfirst'],
+                Perl_pp_sle => [qw(slt sgt sge)],
                );
 
 while (my ($func, $names) = splice @raw_alias, 0, 2) {
diff --git a/pp.c b/pp.c
index 8d34510..401e1e3 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -2091,54 +2091,40 @@ PP(pp_ncmp)
     }
 }
 
-PP(pp_slt)
+PP(pp_sle)
 {
-    dSP; tryAMAGICbinSET_var(slt_amg,0);
-    {
-      dPOPTOPssrl;
-      const int cmp = (IN_LOCALE_RUNTIME
-                ? sv_cmp_locale(left, right)
-                : sv_cmp(left, right));
-      SETs(boolSV(cmp < 0));
-      RETURN;
-    }
-}
+    dSP;
 
-PP(pp_sgt)
-{
-    dSP; tryAMAGICbinSET_var(sgt_amg,0);
-    {
-      dPOPTOPssrl;
-      const int cmp = (IN_LOCALE_RUNTIME
-                ? sv_cmp_locale(left, right)
-                : sv_cmp(left, right));
-      SETs(boolSV(cmp > 0));
-      RETURN;
-    }
-}
+    int amg_type = sle_amg;
+    int multiplier = 1;
+    int rhs = 1;
 
-PP(pp_sle)
-{
-    dSP; tryAMAGICbinSET_var(sle_amg,0);
-    {
-      dPOPTOPssrl;
-      const int cmp = (IN_LOCALE_RUNTIME
-                ? sv_cmp_locale(left, right)
-                : sv_cmp(left, right));
-      SETs(boolSV(cmp <= 0));
-      RETURN;
+    switch (PL_op->op_type) {
+    case OP_SLT:
+       amg_type = slt_amg;
+       /* cmp < 0 */
+       rhs = 0;
+       break;
+    case OP_SGT:
+       amg_type = sgt_amg;
+       /* cmp > 0 */
+       multiplier = -1;
+       rhs = 0;
+       break;
+    case OP_SGE:
+       amg_type = sge_amg;
+       /* cmp >= 0 */
+       multiplier = -1;
+       break;
     }
-}
 
-PP(pp_sge)
-{
-    dSP; tryAMAGICbinSET_var(sge_amg,0);
+    tryAMAGICbinSET_var(amg_type,0);
     {
       dPOPTOPssrl;
       const int cmp = (IN_LOCALE_RUNTIME
                 ? sv_cmp_locale(left, right)
                 : sv_cmp(left, right));
-      SETs(boolSV(cmp >= 0));
+      SETs(boolSV(cmp * multiplier < rhs));
       RETURN;
     }
 }