Implement distributivity in $scalar ~~ @array
[p5sagit/p5-mst-13.2.git] / pp_ctl.c
index c601f7c..46636f7 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -4000,12 +4000,6 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other)
     SV *e = TOPs;      /* e is for 'expression' */
     SV *d = TOPm1s;    /* d is for 'default', as in PL_defgv */
 
-#   define SM_SEEN_THIS(sv) hv_exists_ent(seen_this, \
-       sv_2mortal(newSViv(PTR2IV(sv))), 0)
-
-#   define SM_SEEN_OTHER(sv) hv_exists_ent(seen_other, \
-       sv_2mortal(newSViv(PTR2IV(sv))), 0)
-
     if (SvAMAGIC(e)) {
        SV * const tmpsv = amagic_call(d, e, smart_amg, 0);
        if (tmpsv) {
@@ -4265,8 +4259,10 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other)
                        if (this_elem || other_elem)
                            RETPUSHNO;
                    }
-                   else if (SM_SEEN_THIS(*this_elem)
-                        || SM_SEEN_OTHER(*other_elem))
+                   else if (hv_exists_ent(seen_this,
+                               sv_2mortal(newSViv(PTR2IV(*this_elem))), 0) ||
+                           hv_exists_ent(seen_other,
+                               sv_2mortal(newSViv(PTR2IV(*other_elem))), 0))
                    {
                        if (*this_elem != *other_elem)
                            RETPUSHNO;
@@ -4307,28 +4303,19 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other)
            destroy_matcher(matcher);
            RETPUSHNO;
        }
-       else if (SvNIOK(d)) {
+       else if (!SvOK(d)) {
+           /* undef ~~ array */
+           const I32 this_len = av_len(MUTABLE_AV(SvRV(e)));
            I32 i;
 
-           for(i = 0; i <= AvFILL(MUTABLE_AV(SvRV(e))); ++i) {
+           for (i = 0; i <= this_len; ++i) {
                SV * const * const svp = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE);
-               if (!svp)
-                   continue;
-               
-               PUSHs(d);
-               PUSHs(*svp);
-               PUTBACK;
-               if (CopHINTS_get(PL_curcop) & HINT_INTEGER)
-                   (void) pp_i_eq();
-               else
-                   (void) pp_eq();
-               SPAGAIN;
-               if (SvTRUEx(POPs))
+               if (!svp || !SvOK(*svp))
                    RETPUSHYES;
            }
            RETPUSHNO;
        }
-       else if (SvPOK(d)) {
+       else {
            const I32 this_len = av_len(MUTABLE_AV(SvRV(e)));
            I32 i;
 
@@ -4336,11 +4323,12 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other)
                SV * const * const svp = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE);
                if (!svp)
                    continue;
-               
+
                PUSHs(d);
                PUSHs(*svp);
                PUTBACK;
-               (void) pp_seq();
+               /* infinite recursion isn't supposed to happen here */
+               (void) do_smartmatch(NULL, NULL);
                SPAGAIN;
                if (SvTRUEx(POPs))
                    RETPUSHYES;